This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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);

Maybe:

  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
program.

+      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.

Thanks,

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]