C++ PATCH for c++/69753 (DR141 broke member template lookup)

Markus Trippelsdorf markus@trippelsdorf.de
Tue Feb 16 10:38:00 GMT 2016


On 2016.02.15 at 16:13 -0500, Jason Merrill wrote:
> When we stopped finding function templates with unqualified lookup due to
> the DR141 fix, that exposed bugs in our lookup within the object expression
> scope; an object-expression of the current instantiation does not make the
> expression dependent.  This patch fixes this issue specifically for implicit
> "this->", which is the case in question in this PR; addressing this issue
> more generally will take more work.
> 
> Tested x86_64-pc-linux-gnu, applying to trunk.

> diff --git a/gcc/testsuite/g++.dg/lookup/member3.C b/gcc/testsuite/g++.dg/lookup/member3.C
> new file mode 100644
> index 0000000..f4e097e4
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/lookup/member3.C
> @@ -0,0 +1,17 @@
> +// PR c++/69753
> +// { dg-do compile { target c++11 } }
> +
> +class A {
> +public:
> +  template <typename> void As();
> +  static A *FromWebContents();
> +  A *FromWebContents2();
> +};
> +template <typename T> class B : A {
> +  void FromWebContents() {
> +    auto guest = A::FromWebContents();
> +    guest ? guest->As<T>() : nullptr;
> +    auto guest2 = A::FromWebContents2();
> +    guest2 ? guest2->As<T>() : nullptr;
> +  }
> +};

Please note that clang rejects the testcase in the non static case:

gcc/testsuite/g++.dg/lookup/member3.C:15:22: error: use 'template' keyword to treat 'As' as a dependent template name
    guest2 ? guest2->As<T>() : nullptr;
                     ^
                     template 
1 error generated.

Here is another testcase that every compiler I've tested (clang, icc,
microsoft) accepts, but is rejected by gcc-6:

class A {
public:
  template <class> void m_fn1();
};
A *fn1(int *);
template <typename> class B : A {
  static int *m_fn2() { fn1(m_fn2())->m_fn1<A>(); }
};

-- 
Markus



More information about the Gcc-patches mailing list