public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/107378] New: `get_if` implementation "is not a constant expression"
@ 2022-10-24 15:36 johelegp at gmail dot com
  2022-10-24 15:59 ` [Bug c++/107378] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: johelegp at gmail dot com @ 2022-10-24 15:36 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107378
           Summary: `get_if` implementation "is not a constant expression"
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: johelegp at gmail dot com
                CC: johelegp at gmail dot com
  Target Milestone: ---

See https://godbolt.org/z/cf1T7q6Tj.

```C++
#include <variant>
static_assert([v = std::variant<int*>{}] { return get_if<0>(&v); }());
```

```
<source>:2:67: error: non-constant condition for static assertion
    2 | static_assert([v = std::variant<int*>{}] { return get_if<0>(&v); }());
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
In file included from <source>:1:
<source>:2:67:   in 'constexpr' expansion of '<lambda closure
object><lambda()>{std::variant<int*>{std::__detail::__variant::_Variant_base<int*>{std::__detail::__variant::_Move_assign_base<true,
int*>{std::__detail::__variant::_Copy_assign_base<true,
int*>{std::__detail::__variant::_Move_ctor_base<true,
int*>{std::__detail::__variant::_Copy_ctor_base<true,
int*>{std::__detail::__variant::_Variant_storage<true,
int*>{std::__detail::__variant::_Variadic_union<int*>{std::__detail::__variant::_Uninitialized<int*,
true>{0}}, 0}}}}}}}}.<lambda()>()'
<source>:2:60:   in 'constexpr' expansion of 'std::get_if<0, int*>((& v))'
/opt/compiler-explorer/gcc-trunk-20221024/include/c++/13.0.0/variant:1183:11:
error: '((&<anonymous>.<lambda()>::__v) != 0)' is not a constant expression
 1183 |       if (__ptr && __ptr->index() == _Np)
      |           ^~~~~
Compiler returned: 1
```

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

end of thread, other threads:[~2022-10-25  6:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-24 15:36 [Bug libstdc++/107378] New: `get_if` implementation "is not a constant expression" johelegp at gmail dot com
2022-10-24 15:59 ` [Bug c++/107378] " pinskia at gcc dot gnu.org
2022-10-24 16:20 ` mpolacek at gcc dot gnu.org
2022-10-24 16:55 ` pinskia at gcc dot gnu.org
2022-10-24 18:59 ` johelegp at gmail dot com
2022-10-24 20:43 ` ppalka at gcc dot gnu.org
2022-10-24 22:00 ` johelegp at gmail dot com
2022-10-25  6:57 ` rguenth 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).