[PATCH] PR19095 Undefined reference to friend template function defined inside template class

suyog sarda sardask01 at gmail.com
Mon Apr 14 22:39:34 PDT 2014


On Tue, Apr 15, 2014 at 5:01 AM, Richard Smith <richard at metafoo.co.uk>wrote:

> On Mon, Apr 14, 2014 at 1:09 AM, suyog sarda <sardask01 at gmail.com> wrote:
>
>> Hi Richard,
>>
>> Thanks for the review. I Agree to your explaination. Following are the
>> points what i understood :
>>
>> 1. setInstantiatedFromMemberTemplate call should not be skipped since it
>> causes mix up of  template parameter list numbering and wrong
>> substitutions,
>>     which is clearly visible in the test case as well.
>>
>
> More fundamentally, it shouldn't be skipped because this function is
> instantiated from a "member template" (it's not actually a member, but this
> really means class-scope template, not member template).
>
>
>> 2. When C is instantiated twice, it should throw re-definition error of
>> function f, which is not done (with or without my patch).
>>
>
> That should be handled by the 'if (isFriend) {' loop starting at around
> line 1424.
>
>
>>  3. In the same function call
>> 'TemplateDeclInstantiator::VisitFunctionDecl', there is a check 'if
>> (isFriend)'.
>>     There is a standard described '[temp.friend] p4 (DR329)' inside that
>> check, which checks if the *FunctionDecl D *is Declared as well as
>> Defined (isThisDeclarationADefintion).
>>     In my opinion, at this point the function defintion is not being set
>> for friend function defined inside the class template.
>>
>
> There's also something strange going on in VisitFunctionTemplateDecl --
> that code is also calling setInstantiatedFromMemberTemplate for a friend
> template definition. So at least there appears to be some redundancy here.
>
> 4. While debugging, it is seen that, the *FunctionDecl D *is *defined *holds
>> true but '*Function->isDefined(Definition)*' evaluates to false (I did
>> not get why it evaluates to false),                 because of which
>> re-defintion error is not emitted.
>>
>
> The function isn't defined because we've not instantiated its definition
> yet; that's probably to be expected.
>

The whole point of conflict is happening because of this only - the
function isn't defined because its not instantiated yet, because of which
the call to function cannot find the definition, even though the definition
should be independent to instantiation of class template.


>
>
>> There is a similar bug for operator overloading - Bug 14785. There also
>> same case is happening - not able to identify if friend function (in 14785
>> its operator overloading function) is defined inside class template.
>>
>> Can you please help me out if my above analysis is correct as well as
>> indicate where/how to set the definition of the declared function? Your
>> help is highly appreciated.
>>
>
> I don't get see what's going wrong, but I suspect something in
> FunctionDecl::getTemplateInstantiationPattern() is broken.
>

I will look at this and try to see i can find something in it. (Though Use
case wise its always better to define friend function outside the class.)



-- 
With regards,
Suyog Sarda
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140415/905957e3/attachment.html>


More information about the cfe-commits mailing list