diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 29c6bbd3230..f861fb3e343 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-10-21 Marek Polacek + + PR c++/92062 - ODR-use ignored for static member of class template. + * pt.c (has_value_dependent_address): Strip location wrappers. + 2019-10-21 Marek Polacek PR c++/92106 - ICE with structured bindings and -Wreturn-local-addr. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 7f7f99297c0..e154cac7b21 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -6542,6 +6542,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/ChangeLog b/gcc/testsuite/ChangeLog index 7365a393a7d..ba280a1beaf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-10-21 Marek Polacek + + 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 PR c++/92106 - ICE with structured bindings and -Wreturn-local-addr. 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 struct A { + static const bool x; + static_assert(&x, ""); // odr-uses A<...>::x +}; + +int g; + +template +const bool A::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 struct A { + static const bool x; + enum { force_instantiation =! &x}; // odr-uses A<...>::x +}; + +int g; + +template +const bool A::x = (g = 42, false); + +void f(A<0>) {} // A<0> must be complete, so is instantiated +int main() +{ + if (g != 42) + __builtin_abort (); +}