diff --git a/src/lib_cxx/data/parser/cxx/CxxDiagnosticConsumer.cpp b/src/lib_cxx/data/parser/cxx/CxxDiagnosticConsumer.cpp index c1625e5a..27dbd20e 100644 --- a/src/lib_cxx/data/parser/cxx/CxxDiagnosticConsumer.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxDiagnosticConsumer.cpp @@ -90,6 +90,11 @@ void CxxDiagnosticConsumer::HandleDiagnostic(clang::DiagnosticsEngine::Level lev } const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(sourceManager.getFileID(loc)); + if (fileEntry == nullptr || !fileEntry->isValid()) + { + fileEntry = sourceManager.getFileEntryForID(sourceManager.getMainFileID()); + } + if (fileEntry != nullptr && fileEntry->isValid()) { filePath = m_canonicalFilePathCache->getCanonicalFilePath(fileEntry); diff --git a/src/test/CxxParserTestSuite.h b/src/test/CxxParserTestSuite.h index eb0e7288..24b359d8 100644 --- a/src/test/CxxParserTestSuite.h +++ b/src/test/CxxParserTestSuite.h @@ -4057,6 +4057,17 @@ public: )); } + void test_cxx_parser_catches_error_in_macro_expasdsadansion() + { + std::shared_ptr client = parseCode( + "void foo() {} \n", { L"-include nothing" } + ); + + TS_ASSERT(utility::containsElement( + client->errors, L"' nothing' file not found <1:10 1:10>" + )); + } + void test_cxx_parser_catches_error_in_macro_expansion() { std::shared_ptr client = parseCode( @@ -4068,7 +4079,7 @@ public: client->errors, L"'this_path_does_not_exist.txt' file not found <2:10 2:10>" )); } - + void test_cxx_parser_finds_location_of_line_comment() { std::shared_ptr client = parseCode( diff --git a/src/test/helper/TestParserClient.h b/src/test/helper/TestParserClient.h index 74b41484..c22e11b6 100644 --- a/src/test/helper/TestParserClient.h +++ b/src/test/helper/TestParserClient.h @@ -168,7 +168,10 @@ private: bool fatal, bool indexed) override { - errors.push_back(addLocationSuffix(message, location)); + if (location.isValid()) + { + errors.push_back(addLocationSuffix(message, location)); + } } std::vector* getBinForSymbolKind(SymbolKind symbolType)