aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2021-02-25 16:38:08 -0500
committerPatrick Palka <ppalka@redhat.com>2021-02-25 16:38:08 -0500
commit676f6f3277181662cf3ed07769edfa2d4fb7df28 (patch)
treec61df9191b1964205ac5d2a49f343c08616f50c0 /gcc
parent2ffc26458dd7ba7b3fa00897f2d8c6cd24ba06f3 (diff)
downloadgcc-676f6f3277181662cf3ed07769edfa2d4fb7df28.zip
gcc-676f6f3277181662cf3ed07769edfa2d4fb7df28.tar.gz
gcc-676f6f3277181662cf3ed07769edfa2d4fb7df28.tar.bz2
c++: Fix CTAD of single-element initializer list [PR99103]
When determining whether to rule out initializer-list constructors during CTAD with a single-element initializer list (as per P0702), the element type's cv-qualifiers should be irrelevant. This patch fixes this by making is_spec_or_derived strip cv-qualifiers from the supplied expression type. In passing, I noticed in maybe_aggr_guide we were calling is_spec_or_derived with swapped arguments. This led us to prefer the aggregate deduction candidate over copying deduction in the second testcase below with -std=c++20. gcc/cp/ChangeLog: PR c++/99103 * pt.c (is_spec_or_derived): Drop cv-qualifiers from 'etype'. (maybe_aggr_guide): Fix order of arguments to is_spec_or_derived. gcc/testsuite/ChangeLog: PR c++/99103 * g++.dg/cpp1z/class-deduction79.C: New test. * g++.dg/cpp1z/class-deduction80.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/pt.c3
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/class-deduction79.C10
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/class-deduction80.C9
3 files changed, 21 insertions, 1 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 3576e0e..0623e92 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -28833,6 +28833,7 @@ is_spec_or_derived (tree etype, tree tmpl)
if (!etype || !CLASS_TYPE_P (etype))
return false;
+ etype = cv_unqualified (etype);
tree type = TREE_TYPE (tmpl);
tree tparms = (INNERMOST_TEMPLATE_PARMS
(DECL_TEMPLATE_PARMS (tmpl)));
@@ -28863,7 +28864,7 @@ maybe_aggr_guide (tree tmpl, tree init, vec<tree,va_gc> *args)
if (args->length() == 1)
{
tree val = (*args)[0];
- if (is_spec_or_derived (tmpl, TREE_TYPE (val)))
+ if (is_spec_or_derived (TREE_TYPE (val), tmpl))
return NULL_TREE;
}
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction79.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction79.C
new file mode 100644
index 0000000..ebbe2b2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction79.C
@@ -0,0 +1,10 @@
+// PR c++/99103
+// { dg-do compile { target c++17 } }
+#include <initializer_list>
+
+template <class T>
+struct S { S(std::initializer_list<T>); };
+
+extern const S<int> x;
+using type = decltype(S{x});
+using type = S<int>; // not S<S<int>>
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction80.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction80.C
new file mode 100644
index 0000000..5ccfc93
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction80.C
@@ -0,0 +1,9 @@
+// PR c++/99103
+// { dg-do compile { target c++17 } }
+
+template <class T> struct X { T a; };
+template <class T> struct Y : X<T> {};
+
+extern const Y<int> y;
+using type = decltype(X{y});
+using type = X<int>; // not X<Y<int>>