forked from OSchip/llvm-project
[clangd] Do not drop diagnostics from macros
if they still end up being in the main file. llvm-svn: 347574
This commit is contained in:
parent
105fc1a5f3
commit
e8ccb8238d
|
@ -79,7 +79,7 @@ Range diagnosticRange(const clang::Diagnostic &D, const LangOptions &L) {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -159,7 +159,9 @@ TEST(DiagnosticsTest, ClangTidy) {
|
|||
"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) {
|
||||
|
@ -181,6 +183,27 @@ 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";
|
||||
|
|
Loading…
Reference in New Issue