Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -4049,6 +4049,22 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
if (funcdecl.canInferAttributes(sc))
funcdecl.initInferAttributes();

/* Warn about external function declarations that may become incorrect
* when @safe is made the default.
*
* extern(D) virtual functions are ok because the compiler will check
* them when they are overridden.
*/
if (funcdecl.isExternal()
&& funcdecl.type.toTypeFunction().trust == TRUST.default_
&& !(funcdecl.isVirtual()
&& (funcdecl.linkage == LINK.d || funcdecl.linkage == LINK.default_)))
{
deprecation(funcdecl.loc,
"`extern` function `%s` should be marked explicitly as `@safe`, `@system`, or `@trusted`",
funcdecl.toPrettyChars);
}

Module.dprogress++;
funcdecl.semanticRun = PASS.semanticdone;

Expand Down
7 changes: 7 additions & 0 deletions src/dmd/func.d
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,13 @@ extern (C++) class FuncDeclaration : Declaration
return false;
}

final bool isExternal()
{
if (fbody || storage_class & STC.disable)
return false;
return (storage_class & STC.extern_) || (linkage != LINK.default_);
}

/**********************************
* Decide if attributes for this function can be inferred from examining
* the function body.
Expand Down
2 changes: 1 addition & 1 deletion test/compilable/compile1.d
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ template test8163(T...)
}

enum N = 2; // N>=2 triggers the bug
extern Point[N] bar();
@system extern Point[N] bar();

void foo()
{
Expand Down
Loading