aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2019-10-21 18:45:45 +0000
committerMarek Polacek <polacek@redhat.com>2019-10-21 18:45:45 +0000
commit2623ecead9b850ac7d79e564ae157dba3dd6d714 (patch)
tree65f87ce073121c8d4bd994dcf4e5e74123b412fd /gcc/testsuite
parent5466bb1deb8a8f73c877cb761c4cee0e07606879 (diff)
PR c++/92062 - ODR-use ignored for static member of class template.
has_value_dependent_address wasn't stripping location wrappers so it gave the wrong answer for "&x" in the static_assert. That led us to thinking that the expression isn't instantiation-dependent, and we skipped static initialization of A<0>::x. This patch adds stripping so that has_value_dependent_address gives the same answer as it used to before the location wrappers addition. * pt.c (has_value_dependent_address): Strip location wrappers. * g++.dg/cpp0x/constexpr-odr1.C: New test. * g++.dg/cpp0x/constexpr-odr2.C: New test. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@277266 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-odr1.C19
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-odr2.C19
3 files changed, 44 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7365a393a7d..ba280a1beaf 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,11 @@
2019-10-21 Marek Polacek <polacek@redhat.com>
+ PR c++/92062 - ODR-use ignored for static member of class template.
+ * g++.dg/cpp0x/constexpr-odr1.C: New test.
+ * g++.dg/cpp0x/constexpr-odr2.C: New test.
+
+2019-10-21 Marek Polacek <polacek@redhat.com>
+
PR c++/92106 - ICE with structured bindings and -Wreturn-local-addr.
* g++.dg/cpp1z/decomp50.C: New test.
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-odr1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-odr1.C
new file mode 100644
index 00000000000..cf3f95f0565
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-odr1.C
@@ -0,0 +1,19 @@
+// PR c++/92062 - ODR-use ignored for static member of class template.
+// { dg-do run { target c++11 } }
+
+template<int> struct A {
+ static const bool x;
+ static_assert(&x, ""); // odr-uses A<...>::x
+};
+
+int g;
+
+template<int I>
+const bool A<I>::x = (g = 42, false);
+
+void f(A<0>) {} // A<0> must be complete, so is instantiated
+int main()
+{
+ if (g != 42)
+ __builtin_abort ();
+}
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-odr2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-odr2.C
new file mode 100644
index 00000000000..0927488e569
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-odr2.C
@@ -0,0 +1,19 @@
+// PR c++/92062 - ODR-use ignored for static member of class template.
+// { dg-do run { target c++11 } }
+
+template<int> struct A {
+ static const bool x;
+ enum { force_instantiation =! &x}; // odr-uses A<...>::x
+};
+
+int g;
+
+template<int I>
+const bool A<I>::x = (g = 42, false);
+
+void f(A<0>) {} // A<0> must be complete, so is instantiated
+int main()
+{
+ if (g != 42)
+ __builtin_abort ();
+}