[C++ PATCH] C++0x static assertions

Mark Mitchell mark@codesourcery.com
Tue Nov 21 18:39:00 GMT 2006

Doug Gregor wrote:
> Hi Mark,
> Thanks for reviewing my patch. A revised and improved version is
> attached; some comments are inline.

This version looks very goods.  A few nit-picks:

+        error ("%E", message);


  error ("static assertion failed: %E", message);

?  I'll leave this to you, but it might help clue people in that this is
not some rule of C++ that was violated, but rather an assertion in the

+      else if (condition && condition != error_mark_node)
+        error ("invalid condition %<%E%> in static assertion",
+               condition);

I don't like using %E for arbitrary expressions.  If you have some big
complicated thing there, it will try to print it -- but generally not in
the way the programmer wrote it.  (The EDG front end never undumps
expressions in error messages; it just points you at the expression in
the source code.  I think that's better; trying to dump out a C++
expression in a way that makes sense to people is hard.)

But, under what circumstances can we get here?  We've converted an
integral constant expression to bool, and we know that we didn't get an
INTEGER_CST.  I can think of one case:

  static_assert (7 / 0, "X");

which we will refuse to fold.  (You might want a test-case for that,
just in case; it's the kind of thing that's easy to break.)  I'm not
even sure what the semantics of static_assert are supposed to be in that
case. :-)

I would just say:

  error ("non-constant condition for static assertion");

OK with those changes.  Or, if you want, let's discuss further.


Mark Mitchell
(650) 331-3385 x713

More information about the Gcc-patches mailing list