Skip to content

Loading…

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

Closed
wants to merge 1 commit into from

2 participants

@donc
D Programming Language member

No description provided.

@WalterBright
D Programming Language member

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

@donc
D Programming Language member

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.

@WalterBright
D Programming Language member

I incorporated the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 29, 2012
  1. @donc

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

    donc committed
    Use the same error message as 'if'.
Showing with 11 additions and 0 deletions.
  1. +6 −0 src/cond.c
  2. +5 −0 src/staticassert.c
View
6 src/cond.c
@@ -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;
View
5 src/staticassert.c
@@ -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.