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?

Reply via email to