bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] verify: use _Static_assert if available


From: Bruno Haible
Subject: Re: [PATCH] verify: use _Static_assert if available
Date: Sat, 9 Apr 2011 16:32:02 +0200
User-agent: KMail/1.9.9

Pádraig Brady wrote:
> > /* The condition (99 < __GNUC__) is temporary, until we know about the
> >    first G++ release that supports static_assert.  */
> > # if (99 < __GNUC__) && defined __cplusplus
> > #  define HAVE_STATIC_ASSERT 1
> > # endif
> > 
> g++ supports static_assert since 4.3 I think

You are right that it's listed as "implemented" since GCC 4.3 in [1] and [2].

But I got error messages, when I tried it with this test program:

$ cat foo1.cc
#include <assert.h>
static_assert (sizeof (long) > 1, "long too small");
$ /arch/x86-linux/gnu-inst-gcc/4.3.0/bin/g++ -S foo1.cc 
foo1.cc:2: error: expected constructor, destructor, or type conversion before 
'(' token
$ /arch/x86-linux/gnu-inst-gcc/4.4.0/bin/g++ -S foo1.cc 
foo1.cc:2: error: expected constructor, destructor, or type conversion before 
'(' token
$ /arch/x86-linux/gnu-inst-gcc/4.5.0/bin/g++ -S foo1.cc 
foo1.cc:2:15: error: expected constructor, destructor, or type conversion 
before '(' token
$ /arch/x86-linux/gnu-inst-gcc/4.6.0/bin/g++ -S foo1.cc 
foo1.cc:2:15: error: expected constructor, destructor, or type conversion 
before '(' token

The test program ought to be valid according to ISO C++ N3242 sections 7.(1)
and 7.(4).

The reason is that the static_assert assert parsing is only enabled when you
pass -std=c++0x or -std=gnu++0x. It's not enabled by default.

We could use a 'defined __GXX_EXPERIMENTAL_CXX0X__' clause, but that macro is
probably going away some day...

Bruno

[1] http://gcc.gnu.org/projects/cxx0x.html
[2] http://gcc.gnu.org/gcc-4.3/cxx0x_status.html
-- 
In memoriam Georg Elser <http://en.wikipedia.org/wiki/Georg_Elser>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]