diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/SemaCXX/array-bounds.cpp | 10 | ||||
-rw-r--r-- | test/SemaCXX/warn-unreachable.cpp | 19 |
2 files changed, 25 insertions, 4 deletions
diff --git a/test/SemaCXX/array-bounds.cpp b/test/SemaCXX/array-bounds.cpp index c1b3701172..8d0b1e4e30 100644 --- a/test/SemaCXX/array-bounds.cpp +++ b/test/SemaCXX/array-bounds.cpp @@ -73,17 +73,21 @@ void test() { (*array_ptr)[3] = 1; // expected-warning {{array index 3 is past the end of the array (which contains 2 elements)}} } +// FIXME: we should see the next note only 3 times and the following warning once, not twice +// since it is independent of the template parameter 'I'. template <int I> struct S { - char arr[I]; // expected-note 2 {{declared here}} + char arr[I]; // expected-note 4 {{declared here}} }; template <int I> void f() { S<3> s; - s.arr[4] = 0; // expected-warning {{array index 4 is past the end of the array (which contains 3 elements)}} - s.arr[I] = 0; // expected-warning {{array index 5 is past the end of the array (which contains 3 elements)}} + s.arr[4] = 0; // expected-warning 2 {{array index 4 is past the end of the array (which contains 3 elements)}} + s.arr[I] = 0; // expected-warning {{array index 5 is past the end of the array (which contains 3 elements)}} \ + expected-warning {{array index 3 is past the end of the array (which contains 3 elements)}} } void test_templates() { f<5>(); // expected-note {{in instantiation}} + f<3>(); // expected-note {{in instantiation}} } #define SIZE 10 diff --git a/test/SemaCXX/warn-unreachable.cpp b/test/SemaCXX/warn-unreachable.cpp index f36300af4d..3d368759d7 100644 --- a/test/SemaCXX/warn-unreachable.cpp +++ b/test/SemaCXX/warn-unreachable.cpp @@ -98,6 +98,24 @@ void test_unreachable_templates_harness() { test_unreachable_templates<TestUnreachableB>(); } +// Do warn about non-dependent unreachable code in templates +// Warn even if the template is never instantiated + +template<typename T> void test_non_dependent_unreachable_templates() { + TestUnreachableA::foo(); + isUnreachable(); // expected-warning {{will never be executed}} +} + +// Warn only once even if the template is instantiated multiple times + +template<typename T> void test_non_dependent_unreachable_templates2() { + TestUnreachableA::foo(); + isUnreachable(); // expected-warning {{will never be executed}} +} + +template void test_non_dependent_unreachable_templates2<int>(); +template void test_non_dependent_unreachable_templates2<long>(); + // Do warn about explict template specializations, as they represent // actual concrete functions that somebody wrote. @@ -106,4 +124,3 @@ template <> void funcToSpecialize<int>() { halt(); dead(); // expected-warning {{will never be executed}} } - |