Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Clang gives the following error message, which gives some clues to the problem:</p> <pre><code>$ clang -fsyntax-only test.cc -Wall test.cc:7:10: error: call to function 'f' that is neither visible in the template definition nor found by argument-dependent lookup return f(x); ^ test.cc:21:3: note: in instantiation of function template specialization 'A::g&lt;B::C&gt;' requested here A::g(B::C()); ^ test.cc:17:5: note: 'f' should be declared prior to the call site or in namespace 'B' int f(B::C x) { return 2; } ^ 1 error generated. </code></pre> <p>Specifically, you've run into a detail of two-phase lookup of dependent names in template definitions. In C++98, [temp.dep.candidate] says:</p> <blockquote> <p>For a function call that depends on a template parameter, if the function name is an unqualified-id but not a template-id, the candidate functions are found using the usual lookup rules (3.4.1, 3.4.2) except that:</p> <ul> <li>For the part of the lookup using unqualified name lookup (3.4.1), only function declarations with external linkage from the template definition context are found.</li> <li>For the part of the lookup using associated namespaces (3.4.2), only function declarations with external linkage found in either the template definition context or the template instantiation context are found.</li> </ul> </blockquote> <p>Since <code>A::f(B::C x)</code> isn't found using associated namespaces (i.e. argument-dependent lookup), it has to be visible at the template definition site, not just at the point of instantiation.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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