[cfe-commits] r79941 - in /cfe/trunk: lib/Analysis/CFG.cpp test/SemaTemplate/fun-template-def.cpp

Douglas Gregor dgregor at apple.com
Tue Aug 25 08:30:57 PDT 2009


On Aug 24, 2009, at 11:14 PM, Chris Lattner wrote:

> On Aug 24, 2009, at 5:41 PM, Douglas Gregor wrote:
> On Aug 24, 2009, at 3:38 PM, Chris Lattner wrote:
>>> On Aug 24, 2009, at 2:39 PM, Douglas Gregor wrote:
>>>> Author: dgregor
>>>> Date: Mon Aug 24 16:39:56 2009
>>>> New Revision: 79941
>>>>
>>>> URL: http://llvm.org/viewvc/llvm-project?rev=79941&view=rev
>>>> Log:
>>>> Don't try to evaluate an expression that is type- or value- 
>>>> dependent while building the CFG
>>>
>>> Does it really make sense to build a CFG of an uninstantiated  
>>> template?
>>
>> It might. The control flow of a template doesn't really depend on  
>> its template parameters, with two notable exceptions:
>>
>> (1) A dependent function call might end up calling a noreturn  
>> function in every instantiation.
>> (2) A value- or type-dependent expression used in a branch might  
>> evaluate true (or false) in every instantiation.
>>
>> Maybe that's enough reason to turn off the flow-control diagnostics  
>> for templates, but I will point out that Clang's flow-control  
>> diagnostics managed to catch a missing "return" in an  
>> uninstantiated template today, in real code :)
>
> Ok point taken.  Here's another way to look at it: is it worthwhile  
> (in terms of compile time) to check all uninstantiated templates?   
> It would be better to only do these "heavier" semantic checks on  
> inline functions and templates that are actually used in a  
> translation unit rather than in every translation unit that they are  
> parsed in.  This applies equally well to C inline functions as it  
> does to all the fun C++ stuff, it's just that C++ will suffer more  
> if we don't do something like this.
>
> Thoughts?


I find these checks useful (as a programmer), as much in  
uninstantiated templates and inline functions as anywhere else.  
However, I suggest that we delay this discussion until we can quantify  
the actual compile-time cost on, e.g., <algorithm>, <numeric>, or  
<iostream>.

	- Doug



More information about the cfe-commits mailing list