public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] c++: prvalue of array type [PR111286]
@ 2024-02-05 21:32 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2024-02-05 21:32 UTC (permalink / raw)
  To: gcc-patches

Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

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.
---
 gcc/cp/tree.cc                                |  9 +++++----
 gcc/testsuite/g++.dg/cpp0x/initlist-array22.C | 12 ++++++++++++
 2 files changed, 17 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-array22.C

diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index 5c8c05dc168..50dc345ec9a 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -977,11 +977,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
index 00000000000..8629e4be239
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-array22.C
@@ -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{};
+}

base-commit: f1412546ac8999b7f6eeeee8cf967ce3f31794c2
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-05 21:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-05 21:32 [pushed] c++: prvalue of array type [PR111286] Jason Merrill

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).