public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111532] New: tuple get accesses through base element type in constant expression
@ 2023-09-22  0:36 oliverzlee at gmail dot com
  2023-09-22  1:27 ` [Bug c++/111532] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: oliverzlee at gmail dot com @ 2023-09-22  0:36 UTC (permalink / raw)
  To: gcc-bugs

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

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

* [Bug c++/111532] tuple get accesses through base element type in constant expression
  2023-09-22  0:36 [Bug c++/111532] New: tuple get accesses through base element type in constant expression oliverzlee at gmail dot com
@ 2023-09-22  1:27 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-22  1:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 55965
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55965&action=edit
Reduced testcase

It is __no_unique_address__ and empty base class related ...

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

end of thread, other threads:[~2023-09-22  1:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-22  0:36 [Bug c++/111532] New: tuple get accesses through base element type in constant expression oliverzlee at gmail dot com
2023-09-22  1:27 ` [Bug c++/111532] " pinskia 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).