<div dir="ltr"><br><div>Hi all,</div><div><br></div><div>This is with respect to the following test code:</div><div><br></div><div><div>template <class T> decltype(g2(T())) f2();</div><div>int g2(int);</div><div>template <class T> decltype(g2(T())) f2() // { dg-error "g2. was not declared" }</div>
<div>{ return g2(T()); }</div><div>int i2 = f2<int>();</div></div><div><br></div><div>clang++ seems to compile this code but it should throw an error as per the following standard:</div><div><br></div><div><div>Two expressions involving template parameters are considered equivalent if two function definitions containing the expressions would satisfy the one definition rule (3.2), except that the tokens used to name the template parameters may differ as long as a token used to name a template parameter in one expression is replaced by another token that names the same template parameter in the other expression. For determining</div>
<div>whether two dependent names (14.6.2) are equivalent, only the name itself is considered, not the result of name lookup in the context of the template. If multiple declarations of the same function template differ in the result of this name lookup, the result for the first declaration is used.</div>
</div><div><br></div><div>Example:</div><div><br></div><div><div>template <class T> decltype(g(T())) h();</div><div>int g(int);</div><div>template <class T> decltype(g(T())) h()  // redeclaration of h() uses the earlier                                                            lookup</div>
</div><div>{ return g(T()); }                                  // ..although the lookup here does                                                                find g(int)<br></div><div>int i = h<int>();                                   // template argument substitution                                                                  fails; g(int) was not in scope at the                                                            first declaration of h()<br>
</div><div><br></div><div><br></div><div>Is this a potential bug or am I missing something? If yes, it would be great if someone gave some initial pointers as to how to go about fixing it.</div><div><br></div><div>I went through the code as to how two functions with the same signature are handled.</div>
<div>The function bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD, Scope *S,bool MergeTypeWithOld); does the check for the same.</div><div><br></div><div>But I lost track somewhere after instantiation.</div><div>
<br></div><div>Basically the approach I want to take is, after instantiation when it is checked whether the declaration of g(int) is present or not using the function call</div><div><br></div><div>OverloadingResult</div><div>
OverloadCandidateSet::BestViableFunction(Sema &S, SourceLocation Loc,</div><div>                                         iterator &Best,</div><div>                                         bool UserDefinedConversion);</div>
<div><br></div><div>I wish to check it keeping in mind the source location of the function declaration and not definition.</div><div><br></div><div>Any help on this would be really helpful.</div><div><br></div><div><br></div>
<div>Thanks,</div><div>Rahul</div><div><br></div></div>