public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "petr.azmanov at wartsila dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107165] New: Downcasting in constexpr, error: "accessing value of `...Derived::<anonymous>’ through a ‘Derived’ glvalue in a constant expression" Date: Wed, 05 Oct 2022 23:09:18 +0000 [thread overview] Message-ID: <bug-107165-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107165 Bug ID: 107165 Summary: Downcasting in constexpr, error: "accessing value of `...Derived::<anonymous>’ through a ‘Derived’ glvalue in a constant expression" Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: petr.azmanov at wartsila dot com Target Milestone: --- Created attachment 53670 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53670&action=edit copy of the test case from the comment Downcasting in constexpr context is broken if derived class is wrapped in another structure. Tested locally with g++ (Ubuntu 11.2.0-19ubuntu1) 11.2.0 Reproduced with g++ 11.3.0 in Godbolt (https://godbolt.org/z/fvoWhrh41) Isn't reproduced with 12.1 or 12.2. ``` struct Base { int b = 0; }; struct Derived : Base { int d = 2; constexpr bool foo(int x) { return x > d; } }; int main() { constexpr auto test = []() { struct Dummy { Derived derived; }; Dummy d; Base & base = d.derived; static_cast<Derived &>(base).foo(1); // Derived d; // Base & base = d; // static_cast<Derived &>(base).foo(1); return true; }(); return test; } ```
next reply other threads:[~2022-10-05 23:09 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-10-05 23:09 petr.azmanov at wartsila dot com [this message] 2022-10-05 23:15 ` [Bug c++/107165] " pinskia at gcc dot gnu.org 2022-10-05 23:20 ` pinskia at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-107165-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).