Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fix issue 7793 static assert( void_function() ) gives misleading error #847

Closed
wants to merge 1 commit into from

2 participants

Don Clugston Walter Bright
Don Clugston
Collaborator
donc commented March 29, 2012

No description provided.

Walter Bright
Owner

I think a more general fix would be to use Type::checkToBoolean() or even Expression::checkToBoolean().

Don Clugston
Collaborator
donc commented March 30, 2012

Makes sense. Currently it'll run CTFE on anything, eg, a function that returns a struct, and only when it's completed does it give an error message that it can't be converted to bool.

Walter Bright
Owner

I incorporated the changes.

Walter Bright WalterBright closed this June 22, 2012
Brad Roberts braddr referenced this pull request from a commit October 21, 2012
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 29, 2012
Don Clugston Fix issue 7793 static assert( void_function() ) gives misleading error
Use the same error message as 'if'.
bd00380
This page is out of date. Refresh to see the latest.
6  src/cond.c
@@ -248,6 +248,12 @@ int StaticIfCondition::include(Scope *sc, ScopeDsymbol *s)
248 248
         sc->flags |= SCOPEstaticif;
249 249
         Expression *e = exp->semantic(sc);
250 250
         sc->pop();
  251
+        if (e->type == Type::tvoid)
  252
+        {
  253
+            exp->error("expression %s of type void does not have a boolean value", exp->toChars());
  254
+            inc = 2;
  255
+            return 0;
  256
+        }
251 257
         e = e->optimize(WANTvalue | WANTinterpret);
252 258
         if (e->isBool(TRUE))
253 259
             inc = 1;
5  src/staticassert.c
@@ -60,6 +60,11 @@ void StaticAssert::semantic2(Scope *sc)
60 60
     sc = sc->pop();
61 61
     if (e->type == Type::terror)
62 62
         return;
  63
+    if (e->type == Type::tvoid)
  64
+    {
  65
+        exp->error("expression %s of type void does not have a boolean value", exp->toChars());
  66
+        return;
  67
+    }
63 68
     unsigned olderrs = global.errors;
64 69
     e = e->optimize(WANTvalue | WANTinterpret);
65 70
     if (global.errors != olderrs)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.