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

            Bug ID: 111532
           Summary: tuple get accesses through base element type in
                    constant expression
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: oliverzlee at gmail dot com
  Target Milestone: ---

The following does not compile with GCC trunk/13.2/13.1/12.2/12.1 and
-std=c++14:

#include <tuple>

class A
{};

class B : A
{
public:
  constexpr auto base() const -> A
  {
    return static_cast<const A&>(*this);
  }
};

auto main() -> int
{
  constexpr auto x =
    std::get<0>(std::tuple<B>{}).base();
  (void)x;
}

with the following error:
<source>: In function 'int main()':
<source>:18:38:   in 'constexpr' expansion of '(& std::get<0,
B>(std::tuple<B>()))->B::base()'
<source>:18:39: error: accessing value of '<anonymous>.std::_Head_base<0, B,
true>::_M_head_impl' through a 'const A' glvalue in a constant expression
   18 |     std::get<0>(std::tuple<B>{}).base();
      |                                       ^
Compiler returned: 1

This compiles with -std=c++17 and -std=c++20, outside of constant expressions,
and with GCC 11.4.

Here is a godbolt link:
https://godbolt.org/z/x9dvherM6

Reply via email to