diff options
author | Marek Polacek <polacek@redhat.com> | 2019-10-22 15:46:47 +0000 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2019-10-22 15:46:47 +0000 |
commit | 41dd40c44022ce8265bd4274fc25dcdc8c2f737a (patch) | |
tree | 920d0c4c3264c12558be6ae8926471327b89e78b | |
parent | 40f7e4967f98122032cfd074ea49214294855782 (diff) |
PR c++/92062 - ODR-use ignored for static member of class template.
* 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/branches/gcc-9-branch@277295 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/cp/ChangeLog | 3 | ||||
-rw-r--r-- | gcc/cp/pt.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/constexpr-odr1.C | 19 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/constexpr-odr2.C | 19 |
4 files changed, 43 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4071b72694b..e8a17c7edc4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 442e01bfa11..48d8dbb6ad2 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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 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 (); +} |