-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluationAnything related to constant evaluationduplicateResolved as duplicateResolved as duplicatelibstdc++GNU libstdc++ C++ standard libraryGNU libstdc++ C++ standard libraryrejects-valid
Description
The following code snippet cannot be compiled with clang and libstdc++. However, it builds fine with gcc.
#include <string>
using namespace std::string_literals;
int main()
{
static_assert(u"🧸"s.size() == 2);
return 0;
}
❯ clang++ literal.cpp -std=c++20
literal.cpp:7:19: error: static assertion expression is not an integral constant expression
7 | static_assert(u"🧸"s.size() == 2);
| ^~~~~~~~~~~~~~~~~~
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.1.1/../../../../include/c++/15.1.1/bits/basic_string.h:692:2: note: undefined function '_M_construct<const char16_t *>' cannot be used in a constant expression
692 | _M_construct(__s, __s + __n, std::forward_iterator_tag());
| ^
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.1.1/../../../../include/c++/15.1.1/bits/basic_string.h:5006:14: note: in call to 'basic_string(&u"\U0001F9F8"[0], 2, std::allocator<char16_t>())'
5006 | { return basic_string<char16_t>{__str, __len}; }
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
literal.cpp:7:19: note: in call to 'operator""s(&u"\U0001F9F8"[0], 2)'
7 | static_assert(u"🧸"s.size() == 2);
| ^~~~~~
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.1.1/../../../../include/c++/15.1.1/bits/basic_string.h:343:9: note: declared here
343 | _M_construct(_FwdIterator __beg, _FwdIterator __end,
| ^
1 error generated.
~
❯ g++ literal.cpp -std=c++20
~
❯
Distro: Arch Linux
clang version: 20.1.8
gcc and libstdc++ version: 15.1.1
Metadata
Metadata
Assignees
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluationAnything related to constant evaluationduplicateResolved as duplicateResolved as duplicatelibstdc++GNU libstdc++ C++ standard libraryGNU libstdc++ C++ standard libraryrejects-valid