[cfe-commits] r149127 - in /cfe/trunk: include/clang/AST/ include/clang/Parse/ include/clang/Sema/ lib/AST/ lib/Parse/ lib/Sema/ lib/Serialization/ tools/libclang/

Enea Zaffanella zaffanella at cs.unipr.it
Fri Feb 3 02:42:36 PST 2012


On 02/03/2012 09:37 AM, Enea Zaffanella wrote:
> On 02/02/2012 11:48 PM, Eli Friedman wrote:
>> On Fri, Jan 27, 2012 at 1:46 AM, Abramo Bagnara
>> <abramo.bagnara at gmail.com>   wrote:
>>> Author: abramo
>>> Date: Fri Jan 27 03:46:47 2012
>>> New Revision: 149127
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=149127&view=rev
>>> Log:
>>> Added source location for the template keyword in AST template-id expressions.
>
> [...]
>
>> It looks like this change had semantic side-effects; try the following
>> testcase (derived from the gcc testsuite):
>>
>> struct A
>> {
>>     template<int I>
>>     struct B {
>>       static void b1();
>>     };
>> };
>> template<int I>   void f2()
>> {
>>     A::template B<I>::template b1();
>> }
>> template void f2<0>();
>>
>> -Eli
>
> Thanks for spotting this out.
>
> I suspect this is not strictly due to a bug in commit 149127; rather,
> the commit has uncovered a latent issue in the code instantiating
> DependentScopeDeclRefExpr nodes.
> We will try to provide a suitable fix asap.
>
> Enea.


The source of the problem is in method:

   bool DependentScopeDeclRefExpr::hasExplicitTemplateArgs() const;

Before the commit, this was strangely returning a positive answer even 
for expression

     A::template B<I>::template b1();

which has no explicit template arguments at all. As a consequence, 
before the commit we were ending up calling

Sema::BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS,
           const DeclarationNameInfo &NameInfo,
           const TemplateArgumentListInfo &TemplateArgs);

while after the commit we end up calling

Sema::BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS,
           const DeclarationNameInfo &NameInfo);


The attached patch solves the problem by calling function 
BuildQualifiedTemplateIdExpr whenever we have an explicit template 
argument list *or* a valid template keyword location.

As a side effect, the patch also fixes a pretty-printing problem whereby 
in source code such as the following:

template <typename T> void foo() {
   T::template foo();
}

clang was printing the call as if there was an explicit template 
argument list:

template <typename T> void foo() {
     T::template foo<>();
}

After the patch is applied, this is more correctly printed as:

typedef struct __va_list_tag __va_list_tag;
template <typename T> void foo() {
     T::template foo();
}

Testcases have been added for both the original and the pretty-printer 
issues.

OK to commit?

Enea.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ImplicitTemplateArgs.patch
Type: text/x-patch
Size: 11232 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120203/7fa82e96/attachment.bin>


More information about the cfe-commits mailing list