48 lines · cpp
1// RUN: rm -rf %t2// 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++203// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -verify -fmodules-cache-path=%t -I %S/Inputs %s -std=c++204// 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-int5// 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.pcm6 7#include "diag_pragma.h"8 9int foo(int x) {10 // Diagnostics from templates in the module follow the diagnostic state from11 // when the module was built.12#ifdef EXPLICIT_FLAG13 // expected-error@diag_pragma.h:7 {{adding 'int' to a string}}14#else15 // expected-warning@diag_pragma.h:7 {{adding 'int' to a string}}16#endif17 // expected-note@diag_pragma.h:7 {{use array indexing}}18 f(0); // expected-note {{instantiation of}}19 20 g(0); // ok, warning was ignored when building module21 22 // Diagnostics from this source file ignore the diagnostic state from the23 // module.24 void("foo" + x); // expected-warning {{adding 'int' to a string}}25 // expected-note@-1 {{use array indexing}}26 27#pragma clang diagnostic ignored "-Wstring-plus-int"28 29 // Diagnostics from the module ignore diagnostic state changes from this30 // source file.31#ifdef EXPLICIT_FLAG32 // expected-error@diag_pragma.h:7 {{adding 'long' to a string}}33#else34 // expected-warning@diag_pragma.h:7 {{adding 'long' to a string}}35#endif36 // expected-note@diag_pragma.h:7 {{use array indexing}}37 f(0L); // expected-note {{instantiation of}}38 39 g(0L);40 41 void("bar" + x);42 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;47}48