http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55425



--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-11-21 
12:12:19 UTC ---

(In reply to comment #0)

> 

> A return statement is not a return statement if the returned value is __func__

> (also true for non-standard identifiers like __PRETTY_FUNCTION__).

> 

> // good

> //static const char func[] = "function-name";

> //constexpr const char* x() { return func; }

> 

> // bad

> constexpr const char* x() { return __func__;}

> 

> int main() { __builtin_puts(x()); return 0; }



The standard says __func__ is a function-local variable, defined as if by



constexpr const char* x() {

  static const char __func__[] = "function-name ";

  return __func__;

}



Clearly this is not a valid constexpr function.

Changing this would be an extension.





> Situation 2: user literals

> --------------------------

> 

> The (obviously constant) string that the compiler builds from the literal is

> not constant according to the compiler:

> 

> #include <stdio.h>

> 

> constexpr int valid_bin_number(const char* c) { return *c ? ((*c == '1' || *c

> == '0') ? valid_bin_number(c+1) : false ) : true; }

> 

> unsigned int operator"" _bin(const char* str)

> {

> static_assert(valid_bin_number(str), "not a binary number");



'str' is not a constant expression, so 'valid_bin_number(str)' is not a

constant expression either. This is not a bug.





> Situation 3: __m128i type

> --------------------------

> 

> Assigning a literal value to a constexpr __m128 fails because the literal is

> not a literal.



No, the error says __m128 is not a literal type, which I assume is true.

Changing that would be an enhancement request.

Reply via email to