Commit afa8c090 by Marek Polacek Committed by Marek Polacek

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.

From-SVN: r277266
parent e011c010
2019-10-21 Marek Polacek <polacek@redhat.com>
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 <polacek@redhat.com>
PR c++/92106 - ICE with structured bindings and -Wreturn-local-addr.
* typeck.c (maybe_warn_about_returning_address_of_local): Avoid
recursing on null initializer and return false instead.
......
......@@ -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. */
......
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.
......
// 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 ();
}
// 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 ();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment