[libcxx-dev] Problem with __builtin_strlen among compilers

Nevin Liber via libcxx-dev libcxx-dev at lists.llvm.org
Mon Sep 9 11:22:48 PDT 2019


On Mon, Sep 9, 2019 at 8:42 AM Yan Yichen via libcxx-dev <
libcxx-dev at lists.llvm.org> wrote:

> Hi, I’m using libc++ with gcc and have met a problem with code below:
>

Hmmm...  I think __builtin_strlen is constexpr on gcc.

Looking at a more minimal case:

*int* main() { *static_assert*(!__builtin_strlen("")); }

It compiles fine under:

gcc 9.2, libstdc++

/usr/local/gcc/bin/g++-9 -std=c++17 a.cpp

clang 8, libc++

/usr/local/clang/bin/clang++ -std=c++17 a.cpp

gcc 9.2, libc++
/usr/local/gcc/bin/g++-9 -nostdinc++ -I /usr/local/clang/include/c++/v1
-nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc -std=c++17 a.cpp


>  #include <string_view>
>
> constexpr bool test() {
>
>     const char s1[] = "mave";
>
>     std::string_view s2(s1);
>
>     return true;
>
> }
>
> int main() {
>
>     static_assert(test());
>
> }
>

This compiles fine under both gcc 9.2 libstdc++ and clang 8 libc++, but as
you point out fails under gcc 9.2 libc++.
-- 
 Nevin ":-)" Liber  <mailto:nevin at cplusplusguy.com <nevin at eviloverlord.com>>
+1-847-691-1404
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/libcxx-dev/attachments/20190909/254a8c36/attachment.html>


More information about the libcxx-dev mailing list