public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99287] New: std::source_location::function_name breaks constexpr
@ 2021-02-26 12:29 nickgray0 at brown dot edu
  2021-02-26 15:46 ` [Bug c++/99287] " jakub at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: nickgray0 at brown dot edu @ 2021-02-26 12:29 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-03-06 22:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-26 12:29 [Bug c++/99287] New: std::source_location::function_name breaks constexpr nickgray0 at brown dot edu
2021-02-26 15:46 ` [Bug c++/99287] " jakub at gcc dot gnu.org
2021-02-26 15:49 ` jakub at gcc dot gnu.org
2021-03-05 15:30 ` ppalka at gcc dot gnu.org
2021-03-05 15:39 ` jakub at gcc dot gnu.org
2021-03-05 15:57 ` jakub at gcc dot gnu.org
2021-03-05 16:08 ` ppalka at gcc dot gnu.org
2021-03-06 22:10 ` cvs-commit at gcc dot gnu.org
2021-03-06 22:12 ` ppalka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).