]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/92062 - ODR-use ignored for static member of class template.
authorMarek Polacek <polacek@redhat.com>
Tue, 22 Oct 2019 15:46:47 +0000 (15:46 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 22 Oct 2019 15:46:47 +0000 (15:46 +0000)
* 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.

From-SVN: r277295

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp0x/constexpr-odr1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/constexpr-odr2.C [new file with mode: 0644]

index 4071b72694bd748cca6a761821034fd9428743fc..e8a17c7edc48c59431d070de68d872204328dc51 100644 (file)
@@ -7,6 +7,9 @@
        * typeck.c (maybe_warn_about_returning_address_of_local): Avoid
        recursing on null initializer and return false instead.
 
+       PR c++/92062 - ODR-use ignored for static member of class template.
+       * pt.c (has_value_dependent_address): Strip location wrappers.
+
 2019-10-21  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
index 442e01bfa1177dc725bbb0566c89a83757006548..48d8dbb6ad2d80ae6b07760becbefb90ed60ce7c 100644 (file)
@@ -6353,6 +6353,8 @@ check_valid_ptrmem_cst_expr (tree type, tree expr,
 static bool
 has_value_dependent_address (tree op)
 {
+  STRIP_ANY_LOCATION_WRAPPER (op);
+
   /* We could use get_inner_reference here, but there's no need;
      this is only relevant for template non-type arguments, which
      can only be expressed as &id-expression.  */
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-odr1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-odr1.C
new file mode 100644 (file)
index 0000000..cf3f95f
--- /dev/null
@@ -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 (file)
index 0000000..0927488
--- /dev/null
@@ -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 ();
+}