[libcxx-dev] Problem with __builtin_strlen among compilers
Yan Yichen via libcxx-dev
libcxx-dev at lists.llvm.org
Mon Sep 9 06:41:58 PDT 2019
Hi, I'm using libc++ with gcc and have met a problem with code below:
#include <string_view>
constexpr bool test() {
const char s1[] = "mave";
std::string_view s2(s1);
return true;
}
int main() {
static_assert(test());
}
Error message was:
$ g++ -nostdinc++ -I/home/yiyan/.local/include/c++/v1 -nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc -std=c++17 --compile -o /dev/null 1.cc
1.cc: In function 'int main()':
1.cc:8:23: error: non-constant condition for static assertion
8 | static_assert(test());
| ~~~~^~
In file included from /home/yiyan/.local/include/c++/v1/string_view:175,
from 1.cc:1:
1.cc:8:23: in 'constexpr' expansion of 'test()'
1.cc:4:27: in 'constexpr' expansion of 's2.std::__1::basic_string_view<char>::basic_string_view(((const char*)(& s1)))'
/home/yiyan/.local/include/c++/v1/string_view:238:46: in 'constexpr' expansion of 'std::__1::char_traits<char>::length(__s)'
/home/yiyan/.local/include/c++/v1/__string:217:69: error: '__builtin_strlen(((const char*)(& s1)))' is not a constant expression
217 | length(const char_type* __s) _NOEXCEPT {return __builtin_strlen(__s);}
| ~~~~~~~~~~~~~~~~^~~~~
Looks like the root cause is that __builtin_strlen is not constexpr in gcc.
Do you consider to fix this kind of issue?
Best,
Yichen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/libcxx-dev/attachments/20190909/9c9199da/attachment.html>
More information about the libcxx-dev
mailing list