Here, during instantiate_non_dependent_expr, we were getting the wrong answer for any_dependent_bases_p because processing_template_decl was temporarily cleared. Fixed by using uses_template_parms (which doesn't depend on processing_template_decl) on the type we're asking about.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 4c894923eba7d2a86836e43cc1093247a3241a7e Author: Jason Merrill <ja...@redhat.com> Date: Fri Mar 23 11:14:50 2018 -0400 PR c++/85060 - wrong-code with call to base member in template. * search.c (any_dependent_bases_p): Check uses_template_parms rather than processing_template_decl. diff --git a/gcc/cp/search.c b/gcc/cp/search.c index 6bf8b0e70dc..bfeaf2cc819 100644 --- a/gcc/cp/search.c +++ b/gcc/cp/search.c @@ -2619,7 +2619,7 @@ original_binfo (tree binfo, tree here) bool any_dependent_bases_p (tree type) { - if (!type || !CLASS_TYPE_P (type) || !processing_template_decl) + if (!type || !CLASS_TYPE_P (type) || !uses_template_parms (type)) return false; /* If we haven't set TYPE_BINFO yet, we don't know anything about the bases. diff --git a/gcc/testsuite/g++.dg/template/dependent-base3.C b/gcc/testsuite/g++.dg/template/dependent-base3.C new file mode 100644 index 00000000000..e38b968e774 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/dependent-base3.C @@ -0,0 +1,26 @@ +// PR c++/85060 +// { dg-do compile { target c++14 } } + +struct CA { + constexpr int foo() const { return 42; } +}; + +template <class T> +struct CB : CA { }; + +template <class T> +struct CC : CB<T> { + constexpr int bar() const { + const int m = CA::foo(); + return m; + } + + constexpr int baz() const { + const T m = CA::foo(); + return m; + } +}; + +constexpr CC<double> c; + +static_assert( c.bar() == 42, "" );