}
bool isInsideMainFile(const SourceLocation Loc, const SourceManager &M) {
- return Loc.isValid() && M.isWrittenInMainFile(Loc);
+ return Loc.isValid() && M.isWrittenInMainFile(M.getFileLoc(Loc));
}
bool isInsideMainFile(const clang::Diagnostic &D) {
"macro expansion [bugprone-macro-repeated-side-effects]"),
WithNote(Diag(Test.range("macrodef"),
"macro 'SQUARE' defined here "
- "[bugprone-macro-repeated-side-effects]")))));
+ "[bugprone-macro-repeated-side-effects]"))),
+ Diag(Test.range("macroarg"),
+ "multiple unsequenced modifications to 'y'")));
}
TEST(DiagnosticsTest, Preprocessor) {
ElementsAre(Diag(Test.range(), "use of undeclared identifier 'b'")));
}
+TEST(DiagnosticsTest, InsideMacros) {
+ Annotations Test(R"cpp(
+ #define TEN 10
+ #define RET(x) return x + 10
+
+ int* foo() {
+ RET($foo[[0]]);
+ }
+ int* bar() {
+ return $bar[[TEN]];
+ }
+ )cpp");
+ EXPECT_THAT(TestTU::withCode(Test.code()).build().getDiagnostics(),
+ ElementsAre(Diag(Test.range("foo"),
+ "cannot initialize return object of type "
+ "'int *' with an rvalue of type 'int'"),
+ Diag(Test.range("bar"),
+ "cannot initialize return object of type "
+ "'int *' with an rvalue of type 'int'")));
+}
+
TEST(DiagnosticsTest, ToLSP) {
clangd::Diag D;
D.Message = "something terrible happened";