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



--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-11-21 
12:40:29 UTC ---

1) is not valid constexpr IMHO, as the standard says that __func__ works as if

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

   has been provided, but when it is provided, it is not valid constexpr.

2) I don't see why you think you could use something like this at all.

   You are defining a non-constexpr operator "", so str there definitely isn't

   pointer to a string literal, it is a standalone function that might be

   inlined if the inliner choses so.  So it is obvious the static_assert

   which must be evaluated before the optimizations, without depending on

   whether the function is inlined or not, must fail.

   You want something like:

constexpr int

cstrlen (const char *c)

{

  return *c ? cstrlen (c + 1) + 1 : 0;

}



constexpr unsigned int

bin_number (const char *c)

{

  return *c ? (*c == '1' ? (1U << cstrlen (c + 1)) : *c == '0' ? 0 : throw 0) +

bin_number (c + 1) : 0;

}



constexpr unsigned int

operator"" _bin (const char *c)

{

  return bin_number (c);

}



int

main ()

{

  constexpr unsigned int a = 10000_bin;

  (void) a;

  return 0;

}



instead, then you can verify it the same at compile time.

Reply via email to