Skip to content

Commit

Permalink
Merge pull request #7316 from RazvanN7/Issue_17382
Browse files Browse the repository at this point in the history
Fix Issue 17382 - void main(){}pragma(msg,main()); crashes DMD
  • Loading branch information
andralex committed Nov 17, 2017
2 parents 583df4c + 5eec3ed commit aebbe30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ddmd/dsymbolsem.d
Expand Up @@ -2900,7 +2900,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
override void visit(PragmaDeclaration pd)
{
// Should be merged with PragmaStatement
//printf("\tPragmaDeclaration::semantic '%s'\n",toChars());
//printf("\tPragmaDeclaration::semantic '%s'\n", pd.toChars());
if (pd.ident == Id.msg)
{
if (pd.args)
Expand All @@ -2913,6 +2913,11 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
e = resolveProperties(sc, e);
sc = sc.endCTFE();
// pragma(msg) is allowed to contain types as well as expressions
if (e.type && e.type.ty == Tvoid)
{
error(pd.loc, "Cannot pass argument `%s` to `pragma msg` because it is `void`", e.toChars());
return;
}
e = ctfeInterpretForPragmaMsg(e);
if (e.op == TOKerror)
{
Expand Down
9 changes: 9 additions & 0 deletions test/fail_compilation/fail17382.d
@@ -0,0 +1,9 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail17382.d(9): Error: Cannot pass argument `main()` to `pragma msg` because it is `void`
---
*/

void main() {}
pragma(msg, main());

0 comments on commit aebbe30

Please sign in to comment.