From 27a725e2935ad18edd9a92a2555f543d72af391d Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Mon, 10 Oct 2005 14:42:14 +0000 Subject: [PATCH] re PR c++/24275 (Previously accepted code fails with 4.0.2) PR c++/24275 * pt.c (instantiate_decl): Instantiate the initializer of a static data member in the namespace containing the class containing the static data member. PR c++/24275 * g++.dg/template/static19.C: New test. From-SVN: r105173 --- gcc/cp/pt.c | 3 +++ gcc/testsuite/g++.dg/template/static19.C | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 gcc/testsuite/g++.dg/template/static19.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 317d17f3633..2bd96a6d57b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -11558,12 +11558,15 @@ instantiate_decl (tree d, int defer_ok, && !DECL_INITIAL (d) && DECL_INITIAL (code_pattern)) { + tree ns = decl_namespace_context (d); + push_nested_namespace (ns); push_nested_class (DECL_CONTEXT (d)); DECL_INITIAL (d) = tsubst_expr (DECL_INITIAL (code_pattern), args, tf_error | tf_warning, NULL_TREE); pop_nested_class (); + pop_nested_namespace (ns); } /* We restore the source position here because it's used by diff --git a/gcc/testsuite/g++.dg/template/static19.C b/gcc/testsuite/g++.dg/template/static19.C new file mode 100644 index 00000000000..d720127b8f8 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/static19.C @@ -0,0 +1,18 @@ +// PR c++/24275 + +template struct bool_var { + static const bool value = val; +}; +namespace is_inc_ { + struct any { + template any(T const&); + }; + int operator++(any const&); + template struct impl { + static T &x; + static const bool value = sizeof(++x) == 1; + }; +} +template struct is_incr : bool_var< is_inc_::impl::value> {}; +struct not_incr{}; +typedef int sa1[ is_incr::value ? -1 : 1];