1 // RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions -Wuninitialized-const-reference -verify %s 2 3 class A { 4 public: 5 int i; 6 A(){}; 7 A(const A &a){}; 8 A(int i) {} 9 bool operator!=(const A &); 10 }; 11 12 template <class T> 13 void ignore_template(const T &) {} 14 void ignore(const int &i) {} 15 void dont_ignore_non_empty(const int &i) { ; } // Calling this won't silence the warning for you 16 void dont_ignore_block(const int &i) { 17 {} 18 } // Calling this won't silence the warning for you 19 void ignore_function_try_block_maybe_who_knows(const int &) try { 20 } catch (...) { 21 } 22 A const_ref_use_A(const A &a); 23 int const_ref_use(const int &i); 24 A const_use_A(const A a); 25 int const_use(const int i); 26 27 void f(int a) { 28 int i; 29 const_ref_use(i); // expected-warning {{variable 'i' is uninitialized when passed as a const reference argument here}} 30 int j = j + const_ref_use(j); // expected-warning {{variable 'j' is uninitialized when used within its own initialization}} expected-warning {{variable 'j' is uninitialized when passed as a const reference argument here}} 31 A a1 = const_ref_use_A(a1); // expected-warning {{variable 'a1' is uninitialized when passed as a const reference argument here}} 32 int k = const_use(k); // expected-warning {{variable 'k' is uninitialized when used within its own initialization}} 33 A a2 = const_use_A(a2); // expected-warning {{variable 'a2' is uninitialized when used within its own initialization}} 34 A a3(const_ref_use_A(a3)); // expected-warning {{variable 'a3' is uninitialized when passed as a const reference argument here}} 35 A a4 = a3 != a4; // expected-warning {{variable 'a4' is uninitialized when used within its own initialization}} expected-warning {{variable 'a4' is uninitialized when passed as a const reference argument here}} 36 int n = n; // expected-warning {{variable 'n' is uninitialized when used within its own initialization}} 37 const_ref_use(n); 38 39 A a5; 40 const_ref_use_A(a5); 41 42 int m; 43 if (a < 42) 44 m = 1; 45 const_ref_use(m); 46 47 int l; 48 ignore_template(l); // This is a pattern to avoid "unused variable" warnings (e.g. boost::ignore_unused). 49 ignore(l); 50 dont_ignore_non_empty(l); // expected-warning {{variable 'l' is uninitialized when passed as a const reference argument here}} 51 int l1; 52 dont_ignore_block(l1); // expected-warning {{variable 'l1' is uninitialized when passed as a const reference argument here}} 53 int l2; 54 ignore_function_try_block_maybe_who_knows(l2); // expected-warning {{variable 'l2' is uninitialized when passed as a const reference argument here}} 55 } 56