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

Doug Gregor doug.gregor@gmail.com
Tue Nov 21 21:20:00 GMT 2006


On 11/21/06, Mark Mitchell <mark@codesourcery.com> wrote:
> 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.

Sure. I don't have a preference either way.

> +      else if (condition && condition != error_mark_node)
> +        error ("invalid condition %<%E%> in static assertion",
> +               condition);
>
> I don't like using %E for arbitrary expressions.
[snip]
> 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 couldn't even think of a case where it would happen, but I wanted to be sure.
I've added a test case for this.

> I would just say:
>
>   error ("non-constant condition for static assertion");

Okay.

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

Committed to mainline with those changes. Final patch is attached.

  Cheers,
  Doug
-------------- next part --------------
A non-text attachment was scrubbed...
Name: static_assert.patch
Type: application/octet-stream
Size: 16943 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20061121/81f050d2/attachment.obj>


More information about the Gcc-patches mailing list