26 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -verify %s2 3void use_val(int);4void use_const_ref(const int &);5 6// Test that the warning about self initialization is generated only once.7void test_self_init_1warning(bool a) {8 int v = v; // expected-warning {{variable 'v' is uninitialized when used within its own initialization}}9 if (a)10 use_val(v);11 else12 use_const_ref(v);13}14 15// Test that the diagnostic for using an uninitialized variable directly has a16// higher priority than using the same variable via a const reference.17void test_prioritize_use_over_const_ref(bool a) {18 int v; // expected-note {{initialize the variable 'v' to silence this warning}}19 if (a) // expected-warning {{variable 'v' is used uninitialized whenever 'if' condition is false}}20 // expected-note@-1 {{remove the 'if' if its condition is always true}}21 v = 2;22 else23 use_const_ref(v);24 use_val(v); // expected-note {{uninitialized use occurs here}}25}26