public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-4477] c++: substituting CONST_DECL_USING_P enumerators [PR103081]
@ 2022-12-03 15:28 Patrick Palka
0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2022-12-03 15:28 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:b3912122c9dfaba6c8229e8f095885f69782ceda
commit r13-4477-gb3912122c9dfaba6c8229e8f095885f69782ceda
Author: Patrick Palka <ppalka@redhat.com>
Date: Sat Dec 3 10:28:25 2022 -0500
c++: substituting CONST_DECL_USING_P enumerators [PR103081]
We implement class-scope using enum by injecting clones of the enum's
CONST_DECLs as fields of the class, for which CONST_DECL_USING_P is
true, so that qualified lookup naturally finds the enumerators.
Substitution into such a CONST_DECL currently ICEs however, because we
assume the DECL_CONTEXT is always the ENUMERAL_TYPE (which has
TYPE_VALUES) but in this case it's the RECORD_TYPE for the class scope
(which has TYPE_FIELDS).
Since these CONST_DECLs appear to always be non-dependent, this patch
fixes this by shortcutting substitution for CONST_DECLs that have
non-dependent DECL_CONTEXT. This subsumes the existing (and seemingly
dead) DECL_NAMESPACE_SCOPE_P early exit test and also benefits
substitution into ordinary non-dependent CONST_DECLs.
PR c++/103081
gcc/cp/ChangeLog:
* pt.cc (tsubst_copy) <case CONST_DECL>: Generalize
early exit test for namespace-scope decls to check dependence of
the enclosing scope instead. Remove dead early exit test.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/using-enum-10.C: New test.
* g++.dg/cpp2a/using-enum-10a.C: New test.
Diff:
---
gcc/cp/pt.cc | 7 +------
gcc/testsuite/g++.dg/cpp2a/using-enum-10.C | 16 ++++++++++++++++
gcc/testsuite/g++.dg/cpp2a/using-enum-10a.C | 19 +++++++++++++++++++
3 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 31691618d1b..bc8ea06ceae 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -17066,13 +17066,8 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
if (DECL_TEMPLATE_PARM_P (t))
return tsubst_copy (DECL_INITIAL (t), args, complain, in_decl);
- /* There is no need to substitute into namespace-scope
- enumerators. */
- if (DECL_NAMESPACE_SCOPE_P (t))
+ if (!uses_template_parms (DECL_CONTEXT (t)))
return t;
- /* If ARGS is NULL, then T is known to be non-dependent. */
- if (args == NULL_TREE)
- return scalar_constant_value (t);
/* Unfortunately, we cannot just call lookup_name here.
Consider:
diff --git a/gcc/testsuite/g++.dg/cpp2a/using-enum-10.C b/gcc/testsuite/g++.dg/cpp2a/using-enum-10.C
new file mode 100644
index 00000000000..98fe0644729
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/using-enum-10.C
@@ -0,0 +1,16 @@
+// PR c++/103081
+// { dg-do compile { target c++20 } }
+
+enum class Pig { OINK };
+
+struct Hog {
+ using enum Pig;
+ Hog(Pig) { }
+};
+
+template<int>
+void pen() {
+ Hog(Hog::OINK);
+}
+
+template void pen<0>();
diff --git a/gcc/testsuite/g++.dg/cpp2a/using-enum-10a.C b/gcc/testsuite/g++.dg/cpp2a/using-enum-10a.C
new file mode 100644
index 00000000000..daa3221b77a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/using-enum-10a.C
@@ -0,0 +1,19 @@
+// A version of using-enum-10.C where Hog is a template.
+// PR c++/103081
+// { dg-do compile { target c++20 } }
+
+enum class Pig { OINK };
+
+template<int>
+struct Hog {
+ using enum Pig;
+ Hog(Pig) { OINK; }
+};
+
+template<int N>
+void pen() {
+ Hog<1>(Hog<1>::OINK);
+ Hog<N>(Hog<N>::OINK);
+}
+
+template void pen<0>();
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-12-03 15:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-03 15:28 [gcc r13-4477] c++: substituting CONST_DECL_USING_P enumerators [PR103081] Patrick Palka
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).