public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "mpolacek at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106650] [C++23] P2280 - Using unknown references in constant expressions Date: Thu, 16 Nov 2023 22:36:17 +0000 [thread overview] Message-ID: <bug-106650-4-z7Mo8D9hBY@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-106650-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106650 --- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> --- With just --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -7378,6 +7378,8 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, r = build_constructor (TREE_TYPE (t), NULL); TREE_CONSTANT (r) = true; } + else if (TYPE_REF_P (TREE_TYPE (t))) + /* P2280 */; else { if (!ctx->quiet) the test from P2280 behaves as expected: $ xg++ -c z.C -std=c++20 z.C: In function ‘void splash(Swim&)’: z.C:35:33: error: non-constant condition for static assertion 35 | static_assert(pswam->phelps() == 28); // error: lvalue-to-rvalue conversion on a pointer | ~~~~~~~~~~~~~~~~^~~~~ z.C:35:17: error: the value of ‘pswam’ is not usable in a constant expression 35 | static_assert(pswam->phelps() == 28); // error: lvalue-to-rvalue conversion on a pointer | ^~~~~ z.C:34:9: note: ‘pswam’ was not declared ‘constexpr’ 34 | Swim* pswam = &swam; | ^~~~~ z.C:41:31: error: non-constant condition for static assertion 41 | static_assert(swam.lochte() == 12); // error: invoking virtual function on reference | ~~~~~~~~~~~~~~^~~~~ z.C:41:28: error: ‘* & swam’ is not a constant expression 41 | static_assert(swam.lochte() == 12); // error: invoking virtual function on reference | ~~~~~~~~~~~^~ z.C:44:31: error: non-constant condition for static assertion 44 | static_assert(swam.coughlin == 12); // error: lvalue-to-rvalue conversion on an object | ~~~~~~~~~~~~~~^~~~~ z.C:44:31: error: ‘swam’ is not a constant expression z.C: At global scope: z.C:52:36: error: the value of ‘trident’ is not usable in a constant expression 52 | constexpr auto& gallagher = typeid(trident); // error: constexpr-unknown dynamic type | ^~~~~~~ z.C:49:14: note: ‘trident’ was not initialized with a constant expression 49 | extern Swim& trident; | ^~~~~~~ It cannot be that easy, can it?
next prev parent reply other threads:[~2023-11-16 22:36 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-08-16 17:08 [Bug c++/106650] New: " mpolacek at gcc dot gnu.org 2022-12-09 15:27 ` [Bug c++/106650] " pinskia at gcc dot gnu.org 2023-11-16 22:36 ` mpolacek at gcc dot gnu.org [this message] 2023-11-17 21:47 ` mpolacek at gcc dot gnu.org 2023-11-29 22:10 ` cvs-commit at gcc dot gnu.org 2023-11-29 22:24 ` mpolacek 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-106650-4-z7Mo8D9hBY@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).