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

            Bug ID: 99287
           Summary: std::source_location::function_name breaks constexpr
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nickgray0 at brown dot edu
  Target Milestone: ---

the following code seems to break constexpr-ness for std::string_view::find

    #include <source_location>
    #include <string_view>

    template<typename>
    consteval auto f() {
        return std::string_view{
std::source_location::current().function_name() };
    }

    auto main()->int {
        constexpr auto s = f<int>();
        constexpr auto x = s.find("int");
    }



error message: In file included from
/opt/compiler-explorer/gcc-trunk-20210226/include/c++/11.0.1/string_view:781,
                 from <source>:2:
/opt/compiler-explorer/gcc-trunk-20210226/include/c++/11.0.1/bits/string_view.tcc:
In function 'int main()':
<source>:11:30:   in 'constexpr' expansion of
's.std::basic_string_view<char>::find(((const char*)"int"), 0)'
/opt/compiler-explorer/gcc-trunk-20210226/include/c++/11.0.1/string_view:384:26:
  in 'constexpr' expansion of '((const
std::basic_string_view<char>*)this)->std::basic_string_view<char>::find(__str,
__pos, std::char_traits<char>::length(__str))'
/opt/compiler-explorer/gcc-trunk-20210226/include/c++/11.0.1/bits/string_view.tcc:62:20:
error: '(((std::basic_string_view<char>::size_type)((&"consteval auto f() [with
<template-parameter-1-1> = int]"[56]) - ((&"consteval auto f() [with
<template-parameter-1-1> = int]"[21]) + 1))) > 2)' is not a constant expression
   62 |       while (__len >= __n)
      |              ~~~~~~^~~~~~



Replacing std::source_location with the legacy
std::experimental::source_location seems to fix the problem.

Reply via email to