https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103294

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
GCC complains with -std=c++2b:
<source>: In function 'constexpr bool foo()':
<source>:7:33: error: call to non-'constexpr' function
'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const
_CharT*, const _Alloc&) [with <template-parameter-2-1> = std::allocator<char>;
_CharT = char; _Traits = std::char_traits<char>; _Alloc =
std::allocator<char>]'
    7 |         std::string str2{"abcwe"};
      |                                 ^
In file included from
/opt/compiler-explorer/gcc-trunk-20211116/include/c++/12.0.0/string:53,
                 from <source>:2:
/opt/compiler-explorer/gcc-trunk-20211116/include/c++/12.0.0/bits/basic_string.h:535:7:
note: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const
_CharT*, const _Alloc&) [with <template-parameter-2-1> = std::allocator<char>;
_CharT = char; _Traits = std::char_traits<char>; _Alloc =
std::allocator<char>]' declared here
  535 |       basic_string(const _CharT* __s, const _Alloc& __a = _Alloc())
      |       ^~~~~~~~~~~~
<source>: At global scope:
<source>:11:18: error: non-constant condition for static assertion
   11 | static_assert(foo());
      |               ~~~^~
<source>:11:18: error: 'constexpr bool foo()' called in a constant expression
<source>:5:16: note: 'constexpr bool foo()' declared here
    5 | constexpr bool foo()
      |                ^~~

Even libc++ fails to compile the code:
<source>:7:14: error: variable of non-literal type 'std::string' (aka
'basic_string<char, char_traits<char>, allocator<char>>') cannot be defined in
a constexpr function
        std::string str2{"abcwe"};
                    ^
/opt/compiler-explorer/clang-trunk-20211116/bin/../include/c++/v1/string:679:5:
note: 'basic_string<char>' is not literal because it is not an aggregate and
has no constexpr constructors other than copy or move constructors
    basic_string
    ^
1 error generated.

Reply via email to