[Bug c++/100675] std::string_view::find in constexpr function is not constant expression

hewillk at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed May 19 13:05:07 GMT 2021


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

--- Comment #1 from 康桓瑋 <hewillk at gmail dot com> ---
(In reply to 康桓瑋 from comment #0)
> The following code fails in 10.1, 10.2, and 10.3:
> 
> https://godbolt.org/z/soGT9o4GY
> 
> #include <string_view>
> 
> template <class>
> constexpr bool g() {
>   std::string_view s = " ";
>   s.find(" ");
>   return true;
> }
> 
> constexpr bool b = g<void>();          // ok
> template <class T> concept C = g<T>();
> static_assert(C<void>);                // error

If change constexpr to consteval then compiles:

template <class>
consteval bool g() {
  std::string_view s = " ";
  s.find(" ");
  return true;
}


More information about the Gcc-bugs mailing list