Clang Project

clang_source_code/test/Index/pch-warn-as-error-code.cpp
1// RUN: rm -f %t.head.h.pch
2// RUN: c-index-test -write-pch %t.head.h.pch %s -Wuninitialized -Werror=unused 2>&1 | FileCheck -check-prefix=HEAD_DIAGS %s
3// RUN: c-index-test -test-load-source local %s -include %t.head.h -Wuninitialized -Werror=unused 2>&1 | FileCheck -check-prefix=MAIN_DIAGS %s
4
5// Make sure -Wuninitialized works even though the header had a warn-as-error occurrence.
6
7// HEAD_DIAGS: error: unused variable 'x'
8// MAIN_DIAGS: warning: variable 'x1' is uninitialized
9// MAIN_DIAGS-NOT: error: use of undeclared identifier
10
11#ifndef HEADER
12#define HEADER
13
14static void foo_head() {
15  int x;
16}
17
18#else
19
20void test() {
21  int x1; // expected-note {{initialize}}
22  int x2 = x1; // expected-warning {{uninitialized}}
23  (void)x2;
24  foo_head();
25}
26
27#endif
28