jeudi 5 mars 2015

Can constexpr be combined with volatile?

The following snippet works fine in Clang 3.5 but not in GCC 4.9.2:



int main()
{
constexpr volatile int i = 5;
}


with error:



error: both 'volatile' and 'constexpr' cannot be used here


If I inspect the assembly that Clang generates, it shows 5 as expected:



movl $5, -4(%rsp)


In GCC, constexpr int i = 5 is optimized away, but volatile int i = 5 also shows 5 in the assembly. volatile const int i = 5 compiles in both compilers. It's not a foreign concept for something to be both volatile and const at the same time.


Which compiler is correct by the standards?


Aucun commentaire:

Enregistrer un commentaire