diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 3e134f29f..db92acb4c 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -2666,10 +2666,12 @@ bool Preprocessor::validateCfg(const std::string &code, const std::string &cfg) void Preprocessor::validateCfgError(const std::string &cfg) { const std::string id = "ConfigurationNotChecked"; - const std::list locationList; - const Severity::SeverityType severity = Severity::information; - ErrorLogger::ErrorMessage errmsg(locationList, severity, "Skipping configuration '" + cfg + "' because it seems to be invalid. Use -D if you want to check it.", id, false); - errmsg.file0 = file0; + std::list locationList; + ErrorLogger::ErrorMessage::FileLocation loc; + loc.line = 1; + loc.setfile(file0); + locationList.push_back(loc); + ErrorLogger::ErrorMessage errmsg(locationList, Severity::information, "Skipping configuration '" + cfg + "' because it seems to be invalid. Use -D if you want to check it.", id, false); _errorLogger->reportInfo(errmsg); } diff --git a/lib/preprocessor.h b/lib/preprocessor.h index 33b788a8d..577d2b165 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -239,6 +239,10 @@ public: */ std::string handleIncludes(const std::string &code, const std::string &filePath, const std::list &includePaths, std::map &defs, std::list includes = std::list()); + void setFile0(const std::string &f) { + file0 = f; + } + private: void missingInclude(const std::string &filename, unsigned int linenr, const std::string &header, bool userheader); diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index f7d4ad68f..68b2e2add 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -3676,6 +3676,15 @@ private: ASSERT_EQUALS(true, preprocessor.validateCfg("\"\\\"DEBUG()\"", "DEBUG")); ASSERT_EQUALS(false, preprocessor.validateCfg("\"DEBUG()\" DEBUG", "DEBUG")); ASSERT_EQUALS(true, preprocessor.validateCfg("#undef DEBUG", "DEBUG")); + + // #4301: + // #ifdef A + // int a = A; // <- using macro. must use -D so "A" will get a proper value + errout.str(""); + settings.addEnabled("all"); + preprocessor.setFile0("test.c"); + ASSERT_EQUALS(false, preprocessor.validateCfg("int a=A;", "A")); + ASSERT_EQUALS("[test.c:1]: (information) Skipping configuration 'A' because it seems to be invalid. Use -D if you want to check it.\n", errout.str()); } void if_sizeof() { // #4071