From: Ted Kremenek Date: Wed, 23 Feb 2011 01:52:07 +0000 (+0000) Subject: Add test case for PR 9284, a false positive for -Warray-bounds that is now addressed... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3bcc2be17b5cab730a70df07aa8316885535f564;p=clang Add test case for PR 9284, a false positive for -Warray-bounds that is now addressed using basic reachability analysis. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126291 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/SemaCXX/array-bounds.cpp b/test/SemaCXX/array-bounds.cpp index ee7882daea..e82ce60138 100644 --- a/test/SemaCXX/array-bounds.cpp +++ b/test/SemaCXX/array-bounds.cpp @@ -90,15 +90,28 @@ int test_pr9240() { return array[(unsigned long long) 100]; // expected-warning {{array index of '100' indexes past the end of an array (that contains 100 elements)}} } +// PR 9284 - a template parameter can cause an array bounds access to be +// infeasible. template -void myFunc() { +void pr9284() { int arr[3 + (extendArray ? 1 : 0)]; if (extendArray) - arr[3] = 42; + arr[3] = 42; // no-warning } -void f() { - myFunc(); +template +void pr9284b() { + int arr[3 + (extendArray ? 1 : 0)]; // expected-note {{array 'arr' declared here}} + + if (!extendArray) + arr[3] = 42; // expected-warning{{array index of '3' indexes past the end of an array (that contains 3 elements)}} +} + +void test_pr9284() { + pr9284(); + pr9284(); + pr9284b(); + pr9284b(); // expected-note{{in instantiation of function template specialization 'pr9284b' requested here}} }