[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Modules / diag-pragma.cpp
blob4b6318045372a8e74911ca118f507927400a0f97
1 // RUN: rm -rf %t
2 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -emit-module -fmodules-cache-path=%t -fmodule-name=diag_pragma -x c++ %S/Inputs/module.modulemap -std=c++20
3 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -verify -fmodules-cache-path=%t -I %S/Inputs %s -std=c++20
4 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -emit-module -fmodule-name=diag_pragma -x c++ %S/Inputs/module.modulemap -std=c++20 -o %t/explicit.pcm -Werror=string-plus-int
5 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -verify -fmodules-cache-path=%t -I %S/Inputs %s -std=c++20 -DEXPLICIT_FLAG -fmodule-file=%t/explicit.pcm
7 #include "diag_pragma.h"
9 int foo(int x) {
10 // Diagnostics from templates in the module follow the diagnostic state from
11 // when the module was built.
12 #ifdef EXPLICIT_FLAG
13 // expected-error@diag_pragma.h:7 {{adding 'int' to a string}}
14 #else
15 // expected-warning@diag_pragma.h:7 {{adding 'int' to a string}}
16 #endif
17 // expected-note@diag_pragma.h:7 {{use array indexing}}
18 f(0); // expected-note {{instantiation of}}
20 g(0); // ok, warning was ignored when building module
22 // Diagnostics from this source file ignore the diagnostic state from the
23 // module.
24 void("foo" + x); // expected-warning {{adding 'int' to a string}}
25 // expected-note@-1 {{use array indexing}}
27 #pragma clang diagnostic ignored "-Wstring-plus-int"
29 // Diagnostics from the module ignore diagnostic state changes from this
30 // source file.
31 #ifdef EXPLICIT_FLAG
32 // expected-error@diag_pragma.h:7 {{adding 'long' to a string}}
33 #else
34 // expected-warning@diag_pragma.h:7 {{adding 'long' to a string}}
35 #endif
36 // expected-note@diag_pragma.h:7 {{use array indexing}}
37 f(0L); // expected-note {{instantiation of}}
39 g(0L);
41 void("bar" + x);
43 if (x = DIAG_PRAGMA_MACRO) // expected-warning {{using the result of an assignment as a condition without parentheses}} \
44 // expected-note {{place parentheses}} expected-note {{use '=='}}
45 return 0;
46 return 1;