Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

No description provided.

Walter Bright

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

Don Clugston
Collaborator

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

I incorporated the changes.

Brad Roberts braddr referenced this pull request from a commit
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
Commits on Mar 29, 2012
  1. Don Clugston

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

    donc authored
    Use the same error message as 'if'.
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 0 deletions.
  1. +6 −0 src/cond.c
  2. +5 −0 src/staticassert.c
6 src/cond.c
View
@@ -248,6 +248,12 @@ int StaticIfCondition::include(Scope *sc, ScopeDsymbol *s)
sc->flags |= SCOPEstaticif;
Expression *e = exp->semantic(sc);
sc->pop();
+ if (e->type == Type::tvoid)
+ {
+ exp->error("expression %s of type void does not have a boolean value", exp->toChars());
+ inc = 2;
+ return 0;
+ }
e = e->optimize(WANTvalue | WANTinterpret);
if (e->isBool(TRUE))
inc = 1;
5 src/staticassert.c
View
@@ -60,6 +60,11 @@ void StaticAssert::semantic2(Scope *sc)
sc = sc->pop();
if (e->type == Type::terror)
return;
+ if (e->type == Type::tvoid)
+ {
+ exp->error("expression %s of type void does not have a boolean value", exp->toChars());
+ return;
+ }
unsigned olderrs = global.errors;
e = e->optimize(WANTvalue | WANTinterpret);
if (global.errors != olderrs)
Something went wrong with that request. Please try again.