Compiling LLVM with GCC 5/6/7 and -std=c++1z fails due to use of std::char_traits constexpr

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 5 23:43:06 PDT 2020


You might want to mail llvm-dev instead, -commits list isn't great for
the questions.

Roman.

On Tue, Oct 6, 2020 at 4:20 AM Dan Bailey via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
>
> Hi,
>
> When trying to compile LLVM using GCC 5.1 => GCC 7.2 (inclusive) with -std=c++1z, using StringRef errors due to the lack of  a constexpr std::char_traits<char>::length():
>
> .../include/llvm/ADT/StringRef.h:85:44: error: call to non-constexpr function ‘static std::size_t std::char_traits<char>::length(const char_type*)’
>        return std::char_traits<char>::length(Str);
>               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
>
> Looking into the issue, StringRef.h uses this logic to gate against using constexpr char_traits:
>
> #if __cplusplus > 201402L
>       return std::char_traits<char>::length(Str);
> #elif ...
>
> However for the GCC version range mentioned above, the -std=c++1z flag generates __cplusplus 201500L or higher despite char_traits not being constexpr.
>
> I think the correct thing to do here might be to use the feature macro instead:
>
> #if __cpp_lib_constexpr_char_traits
>       return std::char_traits<char>::length(Str);
> #elif ...
>
> Any thoughts?
>
> Thanks,
> --
>
> Dan Bailey        | R&D               | ILM Vancouver
> danbailey at ilm.com | 415 746-XXXX Desk | 778 882-XXXX Cell
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list