36 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wuninitialized-const-pointer -verify %s2 3template <class T>4void ignore_template(const T *) {}5void ignore(const int *) {}6void dont_ignore_non_empty(const int *) { ; } 7void dont_ignore_block(const int *) { {} }8void dont_ignore_try_block(const int *) try {9} catch (...) {10}11int const_ptr_use(const int *);12 13void f(int a) {14 int i;15 const_ptr_use(&i); // expected-warning {{variable 'i' is uninitialized when passed as a const pointer argument here}}16 int j = j + const_ptr_use(&j); // expected-warning {{variable 'j' is uninitialized when used within its own initialization}}17 int k = k; // expected-warning {{variable 'k' is uninitialized when used within its own initialization}}18 const_ptr_use(&k);19 20 // Only report if a variable is always uninitialized at the point of use21 int l;22 if (a < 42)23 l = 1;24 const_ptr_use(&l);25 26 // Don't report if the called function is known to be empty.27 int m;28 ignore_template(&m);29 ignore(&m);30 dont_ignore_non_empty(&m); // expected-warning {{variable 'm' is uninitialized when passed as a const pointer argument here}}31 int n;32 dont_ignore_block(&n); // expected-warning {{variable 'n' is uninitialized when passed as a const pointer argument here}}33 int o;34 dont_ignore_try_block(&o); // expected-warning {{variable 'o' is uninitialized when passed as a const pointer argument here}}35}36