C++0x static asserts cannot be used like so: #include <cassert>
/// Enumeration for memory_order typedef enum memory_order { memory_order_relaxed, memory_order_consume, memory_order_acquire, memory_order_release, memory_order_acq_rel, memory_order_seq_cst } memory_order; class a { void store1(void* __v, memory_order __m = memory_order_seq_cst) volatile { assert(__m == memory_order_acquire); assert(__m == memory_order_acq_rel); assert(__m == memory_order_consume); } void store2(void* __v, const memory_order __m = memory_order_seq_cst) { static_assert(__m == memory_order_acquire, "atomic_address::store requirements not met."); static_assert(__m == memory_order_acq_rel, "atomic_address::store requirements not met."); static_assert(__m == memory_order_consume, "atomic_address::store requirements not met."); } }; g++ -std=gnu++0x says: <b...@francisco> /home/bkoz %$bld/H-x86-gcc.20081208/bin/g++ -std=gnu++0x -g teststatic_a.cc teststatic_a.cc: In member function 'void a::store2(void*, memory_order)': teststatic_a.cc:27: error: '__m' cannot appear in a constant-expression teststatic_a.cc:29: error: '__m' cannot appear in a constant-expression teststatic_a.cc:31: error: '__m' cannot appear in a constant-expression There is an interesting comment in the originating boost static assert header, see 'It's not particularly clear how this applies to enum's or typedefs;' http://www.boost.org/doc/libs/1_37_0/boost/static_assert.hpp Now for the legalese: In N2798, 7.1p4: In a static_assert-declaration the constant-expression shall be a constant expression (5.19) that can be contextually converted to bool (Clause 4). 5.18p3 A constant expression is an integral constant expression if it is of integral or enumeration type >From this, I expect the above code to be valid and compile w/o error. -- Summary: static_assert vs. enums Product: gcc Version: unknown Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: bkoz at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38502