uninit-variables-conditional.cpp revision 53b24ebc37e6edd14ed31e2ef7cbed094ee87e51
196d6c4596587df59821da10270d2102da4a49b73Manman Ren// RUN: %clang_cc1 -fsyntax-only -Wconditional-uninitialized -fsyntax-only %s -verify
296d6c4596587df59821da10270d2102da4a49b73Manman Ren
32ea7e73361c11f061e00caa8d9e71e84e6dd8554Dan Gohmanclass Foo {
42ea7e73361c11f061e00caa8d9e71e84e6dd8554Dan Gohmanpublic:
52ea7e73361c11f061e00caa8d9e71e84e6dd8554Dan Gohman  Foo();
62ea7e73361c11f061e00caa8d9e71e84e6dd8554Dan Gohman  ~Foo();
72ea7e73361c11f061e00caa8d9e71e84e6dd8554Dan Gohman  operator bool();
82ea7e73361c11f061e00caa8d9e71e84e6dd8554Dan Gohman};
92ea7e73361c11f061e00caa8d9e71e84e6dd8554Dan Gohman
102ea7e73361c11f061e00caa8d9e71e84e6dd8554Dan Gohmanint bar();
11eb54d423d2e550324446c9d15fa2b2a92843cab5Richard Smithint baz();
12975d83c291821de340eef3c3498104172b375f79Manman Renint init(double *);
132ea7e73361c11f061e00caa8d9e71e84e6dd8554Dan Gohman
14eb54d423d2e550324446c9d15fa2b2a92843cab5Richard Smith// This case flags a false positive under -Wconditional-uninitialized because
15975d83c291821de340eef3c3498104172b375f79Manman Ren// the destructor in Foo fouls about the minor bit of path-sensitivity in
162ea7e73361c11f061e00caa8d9e71e84e6dd8554Dan Gohman// -Wuninitialized.
172ea7e73361c11f061e00caa8d9e71e84e6dd8554Dan Gohmandouble test() {
182ea7e73361c11f061e00caa8d9e71e84e6dd8554Dan Gohman  double x; // expected-note {{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}}
19bc7fbf0d37b286b37d96b033dfaaabf9c729bca8John McCall  if (bar() || baz() || Foo() || init(&x))
20bc7fbf0d37b286b37d96b033dfaaabf9c729bca8John McCall    return 1.0;
21bc7fbf0d37b286b37d96b033dfaaabf9c729bca8John McCall
22bc7fbf0d37b286b37d96b033dfaaabf9c729bca8John McCall  return x; // expected-warning {{variable 'x' is possibly uninitialized when used here}}
23eb54d423d2e550324446c9d15fa2b2a92843cab5Richard Smith}
24975d83c291821de340eef3c3498104172b375f79Manman Ren