Note that there are some explanatory texts on larger screens.

plurals
  1. POAmbiguous member access expression: is Clang rejecting valid code?
    primarykey
    data
    text
    <p>I have some code that, for the purposes of this question, boils down to</p> <pre><code>template&lt;typename T&gt; class TemplateClass : public T { public: void method() {} template&lt;typename U&gt; static void static_method(U u) { u.TemplateClass::method(); } }; class EmptyClass {}; int main() { TemplateClass&lt;TemplateClass&lt;EmptyClass&gt; &gt; c; TemplateClass&lt;EmptyClass&gt;::static_method(c); } </code></pre> <p>I've tried to compile it with several versions of two compilers. GCC 4.2, 4.4, 4.6 accept it without complaint. Clang 2.9 and SVN trunk as of November 14 reject it with the following error message:</p> <pre><code>example.cc:6:38: error: lookup of 'TemplateClass' in member access expression is ambiguous static void static_method(U u) { u.TemplateClass::method(); } ^ example.cc:13:3: note: in instantiation of function template specialization 'TemplateClass&lt;EmptyClass&gt;::static_method&lt;TemplateClass&lt;TemplateClass&lt;EmptyClass&gt; &gt; &gt;' requested here TemplateClass&lt;EmptyClass&gt;::static_method(c); ^ example.cc:2:7: note: lookup in the object type 'TemplateClass&lt;TemplateClass&lt;EmptyClass&gt; &gt;' refers here class TemplateClass : public T { ^ example.cc:2:7: note: lookup from the current scope refers here 1 error generated. </code></pre> <p>Which one is wrong? I can work around Clang by changing</p> <pre><code> static void static_method(U u) { u.TemplateClass::method(); } </code></pre> <p>to</p> <pre><code> static void static_method(U u) { u.TemplateClass&lt;T&gt;::method(); } </code></pre> <p>but I'd like be confident in my understanding of when it's OK to elide the template parameters.</p> <hr> <p>EDIT: I had thought that the ambiguity was between the two instantiations of <code>TemplateClass</code>. The following code compiles with GCC and Clang, calling that hypothesis into doubt:</p> <pre><code>class E {}; template&lt;typename T&gt; class A : public T { public: void method() {} }; int main() { A&lt;A&lt;E&gt; &gt; a; a.A::method(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload