]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: c++26 regression fixes
authorJason Merrill <jason@redhat.com>
Fri, 14 Jul 2023 13:37:21 +0000 (09:37 -0400)
committerJason Merrill <jason@redhat.com>
Fri, 14 Jul 2023 22:35:40 +0000 (18:35 -0400)
Apparently I wasn't actually running the testsuite in C++26 mode like I
thought I was, so there were some failures I wasn't seeing.

The constexpr hunk fixes regressions with the P2738 implementation; we still
need to use the old handling for casting from void pointers to heap
variables.

PR c++/110344

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_constant_expression): Move P2738 handling
after heap handling.
* name-lookup.cc (get_cxx_dialect_name): Add C++26.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-cast2.C: Adjust for P2738.
* g++.dg/ipa/devirt-45.C: Handle -fimplicit-constexpr.

gcc/cp/constexpr.cc
gcc/cp/name-lookup.cc
gcc/testsuite/g++.dg/cpp0x/constexpr-cast2.C
gcc/testsuite/g++.dg/ipa/devirt-45.C

index cca0435bafcdb546cef66c3f9880702ef1a8c101..9f96a6c41eaf663e77c2df10ea7f4ba607fec8f2 100644 (file)
@@ -7681,17 +7681,6 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
            && !is_std_construct_at (ctx->call)
            && !is_std_allocator_allocate (ctx->call))
          {
-           /* P2738 (C++26): a conversion from a prvalue P of type "pointer to
-              cv void" to a pointer-to-object type T unless P points to an
-              object whose type is similar to T.  */
-           if (cxx_dialect > cxx23)
-             if (tree ob
-                 = cxx_fold_indirect_ref (ctx, loc, TREE_TYPE (type), op))
-               {
-                 r = build1 (ADDR_EXPR, type, ob);
-                 break;
-               }
-
            /* Likewise, don't error when casting from void* when OP is
               &heap uninit and similar.  */
            tree sop = tree_strip_nop_conversions (op);
@@ -7699,6 +7688,16 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
                && VAR_P (TREE_OPERAND (sop, 0))
                && DECL_ARTIFICIAL (TREE_OPERAND (sop, 0)))
              /* OK */;
+           /* P2738 (C++26): a conversion from a prvalue P of type "pointer to
+              cv void" to a pointer-to-object type T unless P points to an
+              object whose type is similar to T.  */
+           else if (cxx_dialect > cxx23
+                    && (sop = cxx_fold_indirect_ref (ctx, loc,
+                                                     TREE_TYPE (type), sop)))
+             {
+               r = build1 (ADDR_EXPR, type, sop);
+               break;
+             }
            else
              {
                if (!ctx->quiet)
index 74565184403c1b4a378614a77a38cbb2f5786464..2d747561e1f5a4ffb01655e66e41843964a51798 100644 (file)
@@ -6731,6 +6731,8 @@ get_cxx_dialect_name (enum cxx_dialect dialect)
       return "C++20";
     case cxx23:
       return "C++23";
+    case cxx26:
+      return "C++26";
     }
 }
 
index b79e8a90131bb5bd5726e65304a10c8d5d1c12ed..3efbd92f043921ceed572f32d7434cbc14a94ff3 100644 (file)
@@ -6,11 +6,11 @@ static int i;
 constexpr void *vp0 = nullptr;
 constexpr void *vpi = &i;
 constexpr int *p1 = (int *) vp0; // { dg-error "cast from .void\\*. is not allowed" }
-constexpr int *p2 = (int *) vpi; // { dg-error "cast from .void\\*. is not allowed" }
+constexpr int *p2 = (int *) vpi; // { dg-error "cast from .void\\*. is not allowed" "" { target c++23_down } }
 constexpr int *p3 = static_cast<int *>(vp0); // { dg-error "cast from .void\\*. is not allowed" }
-constexpr int *p4 = static_cast<int *>(vpi); // { dg-error "cast from .void\\*. is not allowed" }
+constexpr int *p4 = static_cast<int *>(vpi); // { dg-error "cast from .void\\*. is not allowed" "" { target c++23_down } }
 constexpr void *p5 = vp0;
 constexpr void *p6 = vpi;
 
 constexpr int *pi = &i;
-constexpr bool b = ((int *)(void *) pi == pi); // { dg-error "cast from .void\\*. is not allowed" }
+constexpr bool b = ((int *)(void *) pi == pi); // { dg-error "cast from .void\\*. is not allowed" "" { target c++23_down } }
index c26be21964c22f9143e40a76e6873557972cea7c..019b454835cd395908445c7e4b3a5810e1a7eb6a 100644 (file)
@@ -37,5 +37,5 @@ int main()
 }
 
 /* One invocation is A::foo () other is B::foo () even though the type is destroyed and rebuilt in test() */
-/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*A::foo" 2 "inline"  } } */
+/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*A::foo" 2 "inline" { target { ! implicit_constexpr } } } }*/
 /* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*B::foo" 1 "inline"  } } */