$ cat test.c #include <string.h> char x[strlen("test")]; int test () { return sizeof(x); } $ gcc -Wall -S test.c test.c:2:6: error: variably modified 'x' at file scope 2 | char x[strlen("test")]; | ^ which is okay. But: $ gcc -S -x c++ -Wall test.c $ cat test.s .file "test.c" .text .globl x .bss .type x, @object .size x, 4 x: .zero 4 .text .globl _Z4testv .type _Z4testv, @function _Z4testv: .LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movl $4, %eax popq %rbp .cfi_def_cfa 7, 8 ret .cfi_endproc This was previously rejected: $ gcc-4.8 -x c++ -S test.c test.c:2:22: error: array bound is not an integer constant before ‘]’ token char x[strlen("test")]; ^ test.c: In function ‘int test()’: test.c:5:17: error: ‘x’ was not declared in this scope return sizeof(x); ^ I think this should be invalid. Interestingly, this modified example was accepted as C and rejected as C++ by gcc-4.8 $ cat test1.c char x[__builtin_strlen("test")]; int test () { return sizeof(x); } $ gcc-4.8 -S test.c $ gcc-4.8 -x c++ -S test.c test.c:2:22: error: array bound is not an integer constant before ‘]’ token char x[strlen("test")]; ^ test.c: In function ‘int test()’: test.c:5:17: error: ‘x’ was not declared in this scope return sizeof(x); ^
so current trunk accepts the variant test1.c with __builtin_strlen both C and C++: $ gcc -Wall -S test1.c $ gcc -x c++ -Wall -S test1.c Don't know it that is valid.
It's a GNU extension in C++, so we can decide whether it's valid or not.
As Jonathan already mentioned, treating __builtin_strlen("string") (among other string function calls) as a constant integer expression is a useful extension accepted by several C++ compilers, including Clang and ICC 18 (see also pr80265). G++ accepts the test case in C++ 11 mode and later, but rejects it with an error in C++ 98 mode. Since C++ requires array bounds to be constant expressions and calls to functions are not such expressions, it might be worth issuing a pedantic warning on the strlen case in C++ 11 mode and later.
Let me confirm this for the missing pedantic warning.