[cfe-commits] r125640 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td include/clang/Sema/Sema.h lib/Sema/SemaChecking.cpp lib/Sema/SemaExpr.cpp test/Analysis/out-of-bounds.c test/Sema/array-bounds.c

Ted Kremenek kremenek at apple.com
Thu Feb 17 09:48:36 PST 2011


On Feb 17, 2011, at 9:25 AM, Chris Lattner wrote:

> 
> On Feb 17, 2011, at 9:11 AM, Ted Kremenek wrote:
> 
>>> This breaks the Chrome build, where we have some code like this:
>>> 
>>> template <bool extendArray>
>>> void myFunc() {
>>>    int arr[3 + (extendArray ? 1 : 0)];
>>> 
>>>    if (extendArray)
>>>        arr[3] = 42;
>>> }
>>> 
>>> You can always explicitly specialize myFunc for true and false. I think it would make the resulting code strictly more clean. I'm kinda glad the warning fires on this type of construct.
>> 
>> While I agree with that assessment, I'm not certain why we are getting a ConstantArrayType whose size is 3 if the only instantiation of myFunc is for extendArray = false.  I'd like to know *why* the warning is firing here.
> 
> When extendArray is false, the instantiated code is:
> 
>>> template <bool extendArray>
>>> void myFunc() {
>>>    int arr[3 ];
>>> 
>>>    if (false)
>>>        arr[3] = 42;
>>> }
> 
> so it's the same as the other case.

Ah right, I was reading it the other way.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110217/0671e45b/attachment.html>


More information about the cfe-commits mailing list