public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100675] New: std::string_view::find in constexpr function is not constant expression
@ 2021-05-19 10:46 hewillk at gmail dot com
  2021-05-19 13:05 ` [Bug c++/100675] " hewillk at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: hewillk at gmail dot com @ 2021-05-19 10:46 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100675
           Summary: std::string_view::find in constexpr function is not
                    constant expression
           Product: gcc
           Version: 10.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hewillk at gmail dot com
  Target Milestone: ---

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

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

* [Bug c++/100675] std::string_view::find in constexpr function is not constant expression
  2021-05-19 10:46 [Bug c++/100675] New: std::string_view::find in constexpr function is not constant expression hewillk at gmail dot com
@ 2021-05-19 13:05 ` hewillk at gmail dot com
  2021-05-20 12:03 ` redi at gcc dot gnu.org
  2021-05-20 14:22 ` ppalka at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: hewillk at gmail dot com @ 2021-05-19 13:05 UTC (permalink / raw)
  To: gcc-bugs

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;
}

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

* [Bug c++/100675] std::string_view::find in constexpr function is not constant expression
  2021-05-19 10:46 [Bug c++/100675] New: std::string_view::find in constexpr function is not constant expression hewillk at gmail dot com
  2021-05-19 13:05 ` [Bug c++/100675] " hewillk at gmail dot com
@ 2021-05-20 12:03 ` redi at gcc dot gnu.org
  2021-05-20 14:22 ` ppalka at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2021-05-20 12:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Maybe we should just get rid of the __constant_string_p stuff entirely.

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

* [Bug c++/100675] std::string_view::find in constexpr function is not constant expression
  2021-05-19 10:46 [Bug c++/100675] New: std::string_view::find in constexpr function is not constant expression hewillk at gmail dot com
  2021-05-19 13:05 ` [Bug c++/100675] " hewillk at gmail dot com
  2021-05-20 12:03 ` redi at gcc dot gnu.org
@ 2021-05-20 14:22 ` ppalka at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-05-20 14:22 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |ppalka at gcc dot gnu.org
         Resolution|---                         |DUPLICATE

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Already fixed on trunk by r11-3295 (and also fixed for 10.4).  This seems like
ultimately a variant of PR97051, with the is_constant_evaluated() call instead
deeply nested.

*** This bug has been marked as a duplicate of bug 97051 ***

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

end of thread, other threads:[~2021-05-20 14:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-19 10:46 [Bug c++/100675] New: std::string_view::find in constexpr function is not constant expression hewillk at gmail dot com
2021-05-19 13:05 ` [Bug c++/100675] " hewillk at gmail dot com
2021-05-20 12:03 ` redi at gcc dot gnu.org
2021-05-20 14:22 ` 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).