diff --git a/src/lib_parser/data/parser/cxx/PreprocessorCallbacks.cpp b/src/lib_parser/data/parser/cxx/PreprocessorCallbacks.cpp index 0a24005f..0eed421a 100644 --- a/src/lib_parser/data/parser/cxx/PreprocessorCallbacks.cpp +++ b/src/lib_parser/data/parser/cxx/PreprocessorCallbacks.cpp @@ -96,7 +96,7 @@ void PreprocessorCallbacks::MacroExpands( const clang::Token& macroNameToken, const clang::MacroDefinition& macroDirective, clang::SourceRange range, const clang::MacroArgs* args ){ - const std::string& fileStr = m_sourceManager.getFilename(macroNameToken.getLocation()); + const std::string& fileStr = m_sourceManager.getFilename(m_sourceManager.getFileLoc(macroNameToken.getLocation())); if (!fileStr.size()) { return; @@ -116,7 +116,7 @@ ParseLocation PreprocessorCallbacks::getParseLocation(const clang::Token& macroN { clang::SourceLocation location = macroNameTok.getLocation(); return ParseLocation( - m_sourceManager.getFilename(location), + m_sourceManager.getFilename(m_sourceManager.getFileLoc(location)), m_sourceManager.getSpellingLineNumber(location), m_sourceManager.getSpellingColumnNumber(location), m_sourceManager.getSpellingLineNumber(macroNameTok.getEndLoc()), diff --git a/src/test/CxxParserTestSuite.h b/src/test/CxxParserTestSuite.h index c54279ae..e145b293 100644 --- a/src/test/CxxParserTestSuite.h +++ b/src/test/CxxParserTestSuite.h @@ -1781,6 +1781,22 @@ public: TS_ASSERT_EQUALS(client->macroUses[0], "PI <4:12 4:13>"); } + void test_cxx_parser_finds_macro_expand_within_macro() + { + std::shared_ptr client = parseCode( + "#define PI 3.14159265359\n" + "#define TAU (2 * PI)\n" + "void test()\n" + "{\n" + "double i = TAU;" + "};\n" + ); + + TS_ASSERT_EQUALS(client->macroUses.size(), 2); + TS_ASSERT_EQUALS(client->macroUses[0], "TAU <5:12 5:14>"); + TS_ASSERT_EQUALS(client->macroUses[1], "PI <2:18 2:19>"); + } + void test_cxx_parser_finds_usage_of_template_template_parameter_of_template_class_specialized_with_concrete_type() { std::shared_ptr client = parseCode(