public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-4186] c++: templated static local var has value-dep addr [PR98930]
@ 2021-10-05 13:50 Patrick Palka
0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2021-10-05 13:50 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:f3930418cb82000fae3cb4e98e870428800cf295
commit r12-4186-gf3930418cb82000fae3cb4e98e870428800cf295
Author: Patrick Palka <ppalka@redhat.com>
Date: Tue Oct 5 09:50:02 2021 -0400
c++: templated static local var has value-dep addr [PR98930]
Here uses_template_parms returns false for the dependent type A<&impl::i>,
which causes tsubst_aggr_type to think it's non-dependent and not bother
substituting into it, leading to breakage.
This patch fixes this by making has_value_dependent_address also return
true for templated static local variables.
PR c++/98930
gcc/cp/ChangeLog:
* pt.c (has_value_dependent_address): Return true for a static
local variable from a function template.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1z/nontype4.C: New test.
* g++.dg/cpp1z/nontype4a.C: New test.
Diff:
---
gcc/cp/pt.c | 7 +++++++
gcc/testsuite/g++.dg/cpp1z/nontype4.C | 14 ++++++++++++++
gcc/testsuite/g++.dg/cpp1z/nontype4a.C | 14 ++++++++++++++
3 files changed, 35 insertions(+)
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 1dcdffe322a..844b7c14fe4 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -6760,8 +6760,15 @@ has_value_dependent_address (tree op)
if (DECL_P (op))
{
tree ctx = CP_DECL_CONTEXT (op);
+
if (TYPE_P (ctx) && dependent_type_p (ctx))
return true;
+
+ if (VAR_P (op)
+ && TREE_STATIC (op)
+ && TREE_CODE (ctx) == FUNCTION_DECL
+ && type_dependent_expression_p (ctx))
+ return true;
}
return false;
diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype4.C b/gcc/testsuite/g++.dg/cpp1z/nontype4.C
new file mode 100644
index 00000000000..ff476dcf1df
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/nontype4.C
@@ -0,0 +1,14 @@
+// PR c++/98930
+// { dg-do compile { target c++17 } }
+
+template<int*>
+struct A { A() { } };
+
+template<class T>
+void impl() {
+ static int i;
+ static A<&i> a;
+}
+
+template void impl<int>();
+template void impl<char>();
diff --git a/gcc/testsuite/g++.dg/cpp1z/nontype4a.C b/gcc/testsuite/g++.dg/cpp1z/nontype4a.C
new file mode 100644
index 00000000000..5b742926b6d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/nontype4a.C
@@ -0,0 +1,14 @@
+// PR c++/98930
+// { dg-do compile { target c++17 } }
+
+template<int*>
+struct A { };
+
+template<class T>
+auto impl() {
+ static int i;
+ return A<&i>();
+}
+
+using type = decltype(impl<int>());
+using type = decltype(impl<char>()); // { dg-error "conflicting declaration" }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-10-05 13:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-05 13:50 [gcc r12-4186] c++: templated static local var has value-dep addr [PR98930] 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).