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
```

Reply via email to