[cfe-dev] AST template definition VS. template instantiations

Benoit Belley Benoit.Belley at autodesk.com
Thu Aug 26 06:13:30 PDT 2010


Thanks Doug,

Somehow, I missed that function. I was looking for a function with ’Template’ in its name....

Benoit

Le 2010-08-25 à 23:56, Douglas Gregor a écrit :

> 
> On Aug 25, 2010, at 1:21 PM, Benoit Belley wrote:
> 
>> Hi Everyone,
>> 
>> While traversing the Clang AST in a custom static analyzer check (using the RecursiveASTVisitor), I need to determine whether the given function is a template definition because it is part of a template class, template function or a partial specialization of a class template. The reason I need to know this is that template definitions are not fully semantically checked, while template instantiations are. For example, the operator new() referenced by a CXXNewExpr is unresolved in a template definition.
> 
> To be super-precise, the operator new() referenced by a CXXNewExpr *might* be unresolved in a template definition. It depends on whether the types and arguments involved are dependent.
> 
>> Things are not so clear cut because classes and functions can be nested, and therefore one has to look at all of the enclosing scopes to determine if a given FunctionDecl is actually part of a template.
>> 
>> I have come out with the following function to perform such a check and I am wondering if there is an easier way to achieve this:
>> 
>> // Recursively examines the parent contexts to determine if any of them
>> // represents either a function or a class template.
>> static bool isTemplatedContext(DeclContext* ctx) 
>> {
>> [snip code]
>> }
> 
> This is mostly correct, but you don't need it: DeclContext::isDependentContext() does exactly what you need.
> 
> 	- Doug

 
 
Benoit Belley
Sr Principal Developer
M&E-Product Development Group    
 
Autodesk Canada Inc. 
10 Rue Duke
Montreal, Quebec  H3C 2L7 
Canada
 
Direct 514 954-7154
 
 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.gif
Type: image/gif
Size: 651 bytes
Desc: image002.gif
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100826/c29f879f/attachment.gif>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ATT00001..txt
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100826/c29f879f/attachment.txt>


More information about the cfe-dev mailing list