public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-926] c++: implicit deduction guides, protected access
@ 2021-05-19 17:30 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-05-19 17:30 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:873c5188fd5d2e17430cab1522aa36fa62582ea7
commit r12-926-g873c5188fd5d2e17430cab1522aa36fa62582ea7
Author: Jason Merrill <jason@redhat.com>
Date: Tue May 18 12:16:08 2021 -0400
c++: implicit deduction guides, protected access
Jonathan raised this issue with CWG, and there seems to be general agreement
that a deduction guide generated from a constructor should have access to
the same names that the constructor has access to. That seems to be as easy
as setting DECL_CONTEXT.
gcc/cp/ChangeLog:
* pt.c (build_deduction_guide): Treat the implicit deduction guide
as a member of the class.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1z/class-deduction-access1.C: New test.
* g++.dg/cpp1z/class-deduction-access2.C: New test.
Diff:
---
gcc/cp/pt.c | 3 +++
gcc/testsuite/g++.dg/cpp1z/class-deduction-access1.C | 18 ++++++++++++++++++
gcc/testsuite/g++.dg/cpp1z/class-deduction-access2.C | 10 ++++++++++
3 files changed, 31 insertions(+)
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 23d26231849..32cd0b7a6ed 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -28803,6 +28803,9 @@ build_deduction_guide (tree type, tree ctor, tree outer_args, tsubst_flags_t com
DECL_ABSTRACT_ORIGIN (ded_tmpl) = fn_tmpl;
if (ci)
set_constraints (ded_tmpl, ci);
+ /* The artificial deduction guide should have same access as the
+ constructor. */
+ DECL_CONTEXT (ded_fn) = type;
return ded_tmpl;
}
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction-access1.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction-access1.C
new file mode 100644
index 00000000000..2424abb52ef
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction-access1.C
@@ -0,0 +1,18 @@
+// { dg-do compile { target c++17 } }
+
+template<typename T>
+struct Base
+{
+protected:
+ using type = T;
+};
+
+template<typename T>
+struct Cont : Base<T>
+{
+ using argument_type = typename Base<T>::type;
+
+ Cont(T, argument_type) { }
+};
+
+Cont c(1, 1);
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction-access2.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction-access2.C
new file mode 100644
index 00000000000..87f20311e09
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction-access2.C
@@ -0,0 +1,10 @@
+// { dg-do compile { target c++17 } }
+
+struct B {
+protected:
+ struct type {};
+};
+template<typename T> struct D : B {
+ D(T, typename T::type);
+};
+D c = {B(), {}};
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-05-19 17:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-19 17:30 [gcc r12-926] c++: implicit deduction guides, protected access 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).