https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70816
Bug ID: 70816 Summary: bogus error __builtin_strcmp is not a constant expression in a constexpr function Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- G++ accepts most calls to __builtin_strcmp with constant arguments in constexpr contexts, except when the intrinsic is invoked on local arrays defined in a constexpr function. The test case below shows a number of accepted calls along with the one that's incorrectly rejected. $ cat u.c && /home/msebor/build/gcc-trunk-git/gcc/xgcc -B/home/msebor/build/gcc-trunk-git/gcc -Wall -Wextra -Wpedantic -xc++ u.c constexpr int f0 () { return __builtin_strcmp ("a", "b"); } constexpr int f1 () { const char a [] = "a"; const char b [] = "b"; return __builtin_strcmp (a, b); } constexpr int f2 (const char *a, const char *b) { int d = 0; do { d = *b - *a; } while (*a++ && *b++); return d; } constexpr int f3 () { const char s [] = "a"; const char t [] = "b"; const char *a = s; const char *b = t; int d = 0; do { d = *b - *a; } while (*a++ && *b++); return d; } constexpr char a [] = "a"; constexpr char b [] = "b"; constexpr int i0 = __builtin_strcmp ("a", "b"); constexpr int i1 = __builtin_strcmp (a, b); constexpr int i2 = f1 (); constexpr int i3 = f2 (a, b); constexpr int i4 = f3 (); u.c:42:23: in constexpr expansion of ‘f1()’ u.c:10:27: error: ‘__builtin_strcmp(((const char*)(& a)), ((const char*)(& b)))’ is not a constant expression return __builtin_strcmp (a, b); ~~~~~~~~~~~~~~~~~^~~~~~