llvm-project/clang/test/SemaCXX/warn-no-sometimes-uninitialized.cpp
Igor Kudrin 2464313eef
[clang] Fix suppressing diagnostics for uninitialized variables (#148336)
When one kind of diagnostics is disabled, this should not preclude other
diagnostics from displaying, even if they have lower priority. For
example, this should print a warning about passing an uninitialized
variable as a const reference:
```
> cat test.cpp
void foo(const int &);
int f(bool a) {
  int v;
  if (a) {
    foo(v);
    v = 5;
  }
  return v;
}
> clang test.cpp -fsyntax-only -Wuninitialized -Wno-sometimes-uninitialized
```
2025-07-14 14:01:11 -07:00

13 lines
292 B
C++

// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -Wno-sometimes-uninitialized -verify %s
void foo(const int &);
int f(bool a) {
int v;
if (a) {
foo(v); // expected-warning {{variable 'v' is uninitialized when passed as a const reference argument here}}
v = 5;
}
return v;
}