Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Edit: My question is: why should the member function declararions be all well-formed? Since the compiler instantiates the methods only upon their usage, why does it need correct declaration. Consider the above example2 as a possible use-case of this feature.</p> </blockquote> <p>When implicitly instantiating a class template specialization, the compiler has to inspect the complete declarator of that member because it needs to know basic information about the declaration. Such can contribute to the size of the class template specialization. </p> <p>If inspecting the declaration part will find out it's declaring a data-member, the <code>sizeof</code> value of the class will possibly yield a different value. If you would have declared a function pointer instead, this would be the case</p> <pre><code>yes (*f)(typename T::XYZ*); </code></pre> <p>The C++ language is defined in such a way that the type of a declaration is known only once the whole declaration is parsed. </p> <p>You can argue that you put static there, and thus in this case this is not needed to compute its size. But it <em>is</em> needed for name-lookup to know what a name <code>hasXZY&lt;T&gt;::f</code> refers to and that there was declared a name <em>f</em> at all. The compiler will <em>not</em> instantiate the definition of <code>hasXYZ::f</code>, but it will <em>only</em> instantiate the non-definition part of the declaration, to gets its type and adding its name to the class type for name lookup purposes. I believe supporting delayed-instantiation for declaration of names in particular cases where it would possibly work would complicate implementation of C++ compilers and the C++ spec even more, for no comparable benefit.</p> <p>And finally, in your example where you attempt to call it, the compiler <em>has</em> to instantiate the declaration, because it needs to lookup the name <code>f</code>, and for this it <em>needs</em> to know whether that declaration is a function or something else. So I really even theoretically can't see a way your example could work without instantiating the declaration. Note that in any case, these will <em>not</em> instantiate a definition of the function. </p>
    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. 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