https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70816
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |ASSIGNED Last reconfirmed| |2016-06-08 Ever confirmed|0 |1 Known to fail|6.0 |6.1.0, 7.0 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- The same limitation affects other string builtins such as __builtin_strlen or __builtin_strchr. $ cat cst.C && /home/msebor/build/gcc-6-branch/gcc/xgcc -B/home/msebor/build/gcc-6-branch/gcc -S -Wall -Wextra -Wpedantic cst.C -fdump-tree-optimized=/dev/stdout -o/dev/stdout constexpr int chr (int c) { const char a[] = "123"; return __builtin_strchr (a, c) - a; } constexpr int i = chr ('3'); constexpr int cmp (const char *a) { const char b[] = "123"; return __builtin_strcmp (a, b); } constexpr int j = cmp ("345"); constexpr unsigned len () { const char s[] = "123"; return __builtin_strlen (s); } constexpr unsigned n = len (); .file "cst.C" cst.C:7:23: in constexpr expansion of ‘chr(51)’ cst.C:4:27: error: ‘__builtin_strchr(((const char*)(& a)), 51)’ is not a constant expression return __builtin_strchr (a, c) - a; ~~~~~~~~~~~~~~~~~^~~~~~ cst.C:15:23: in constexpr expansion of ‘cmp(((const char*)"345"))’ cst.C:12:27: error: ‘__builtin_strcmp(((const char*)"345"), ((const char*)(& b)))’ is not a constant expression return __builtin_strcmp (a, b); ~~~~~~~~~~~~~~~~~^~~~~~ cst.C:23:28: in constexpr expansion of ‘len()’ cst.C:20:27: error: ‘__builtin_strlen(((const char*)(& s)))’ is not a constant expression return __builtin_strlen (s); ~~~~~~~~~~~~~~~~~^~~