xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/uninit-variables-conditional.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -Wconditional-uninitialized -fsyntax-only %s -verify
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc class Foo {
4*f4a2713aSLionel Sambuc public:
5*f4a2713aSLionel Sambuc   Foo();
6*f4a2713aSLionel Sambuc   ~Foo();
7*f4a2713aSLionel Sambuc   operator bool();
8*f4a2713aSLionel Sambuc };
9*f4a2713aSLionel Sambuc 
10*f4a2713aSLionel Sambuc int bar();
11*f4a2713aSLionel Sambuc int baz();
12*f4a2713aSLionel Sambuc int init(double *);
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc // This case flags a false positive under -Wconditional-uninitialized because
15*f4a2713aSLionel Sambuc // the destructor in Foo fouls about the minor bit of path-sensitivity in
16*f4a2713aSLionel Sambuc // -Wuninitialized.
test()17*f4a2713aSLionel Sambuc double test() {
18*f4a2713aSLionel Sambuc   double x; // expected-note{{initialize the variable 'x' to silence this warning}}
19*f4a2713aSLionel Sambuc   if (bar() || baz() || Foo() || init(&x))
20*f4a2713aSLionel Sambuc     return 1.0;
21*f4a2713aSLionel Sambuc 
22*f4a2713aSLionel Sambuc   return x; // expected-warning {{variable 'x' may be uninitialized when used here}}
23*f4a2713aSLionel Sambuc }
24