Bug 111532 - tuple get accesses through base element type in constant expression with an empty base class
Summary: tuple get accesses through base element type in constant expression with an e...
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 13.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2023-09-22 00:36 UTC by Oliver Lee
Modified: 2023-09-22 15:33 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Reduced testcase (231 bytes, text/plain)
2023-09-22 01:27 UTC, Drea Pinski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Lee 2023-09-22 00:36:48 UTC
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
Comment 1 Drea Pinski 2023-09-22 01:27:43 UTC
Created attachment 55965 [details]
Reduced testcase

It is __no_unique_address__ and empty base class related ...