]> gcc.gnu.org Git - gcc.git/commitdiff
c++: prvalue of array type [PR111286]
authorJason Merrill <jason@redhat.com>
Mon, 5 Feb 2024 18:54:22 +0000 (13:54 -0500)
committerJason Merrill <jason@redhat.com>
Mon, 5 Feb 2024 22:25:14 +0000 (17:25 -0500)
Here we want to build a prvalue array to bind to the T reference, but we
were wrongly trying to strip cv-quals from the array prvalue, which should
be treated the same as a class prvalue.

PR c++/111286

gcc/cp/ChangeLog:

* tree.cc (rvalue): Don't drop cv-quals from an array.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist-array22.C: New test.

(cherry picked from commit c7e8381748f78335e9fef23f363b6a9e4463ce7e)

gcc/cp/tree.cc
gcc/testsuite/g++.dg/cpp0x/initlist-array22.C [new file with mode: 0644]

index 16b8fcb7d57518635e74340758347ae4fcbfae60..c35f15baca2bc59038e3cebd2b61f978cf68937c 100644 (file)
@@ -978,11 +978,12 @@ rvalue (tree expr)
 
   expr = mark_rvalue_use (expr);
 
-  /* [basic.lval]
-
-     Non-class rvalues always have cv-unqualified types.  */
+  /* [expr.type]: "If a prvalue initially has the type "cv T", where T is a
+     cv-unqualified non-class, non-array type, the type of the expression is
+     adjusted to T prior to any further analysis.  */
   type = TREE_TYPE (expr);
-  if (!CLASS_TYPE_P (type) && cv_qualified_p (type))
+  if (!CLASS_TYPE_P (type) && TREE_CODE (type) != ARRAY_TYPE
+      && cv_qualified_p (type))
     type = cv_unqualified (type);
 
   /* We need to do this for rvalue refs as well to get the right answer
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-array22.C b/gcc/testsuite/g++.dg/cpp0x/initlist-array22.C
new file mode 100644 (file)
index 0000000..8629e4b
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/111286
+// { dg-do compile { target c++11 } }
+// { dg-additional-options -Wno-unused }
+
+struct A {
+  A() noexcept {}
+};
+
+void foo() {
+  using T = const A (&)[1];
+  T{};
+}
This page took 0.074984 seconds and 5 git commands to generate.