diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 6995a018a..9f41817a9 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -699,7 +699,8 @@ void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processe processedFile = ostr.str(); } - handleIncludes(processedFile, filename, includePaths); + std::set systemIncludes; + handleIncludes(processedFile, filename, includePaths, systemIncludes); processedFile = replaceIfDefined(processedFile); @@ -1476,6 +1477,7 @@ static int tolowerWrapper(int c) void Preprocessor::handleIncludes(std::string &code, const std::string &filePath, const std::list &includePaths, + std::set &systemIncludes, std::set handledFiles) { std::string::size_type pos = 0; @@ -1540,7 +1542,8 @@ void Preprocessor::handleIncludes(std::string &code, filename = Path::simplifyPath(filename.c_str()); std::string tempFile = filename; std::transform(tempFile.begin(), tempFile.end(), tempFile.begin(), tolowerWrapper); - if (handledFiles.find(tempFile) != handledFiles.end()) + if (handledFiles.find(tempFile) != handledFiles.end() || + (headerType == SystemHeader && systemIncludes.find(tempFile) != systemIncludes.end())) { // We have processed this file already once, skip // it this time to avoid ethernal loop. @@ -1548,7 +1551,10 @@ void Preprocessor::handleIncludes(std::string &code, continue; } - handledFiles.insert(tempFile); + if (headerType == SystemHeader) + systemIncludes.insert(tempFile); + else + handledFiles.insert(tempFile); processedFile = Preprocessor::read(fin, filename, _settings); fin.close(); } @@ -1564,7 +1570,7 @@ void Preprocessor::handleIncludes(std::string &code, // Remove space characters that are after or before new line character processedFile = removeSpaceNearNL(processedFile); - handleIncludes(processedFile, filename, includePaths, handledFiles); + handleIncludes(processedFile, filename, includePaths, systemIncludes, handledFiles); processedFile = "#file \"" + filename + "\"\n" + processedFile + "\n#endfile"; code.insert(pos, processedFile); pos += processedFile.size(); diff --git a/lib/preprocessor.h b/lib/preprocessor.h index 704bd2d54..0239ef8b0 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -209,6 +209,7 @@ private: * There must be a path separator at the end. Default parameter is empty list. * Note that if path from given filename is also extracted and that is used as * a last include path if include file was not found from earlier paths. + * @param systemIncludes System includes * @param handledFiles used in the recursive handling. Should be empty unless * a recursive call is made. * @return modified source code @@ -216,6 +217,7 @@ private: void handleIncludes(std::string &code, const std::string &filePath, const std::list &includePaths, + std::set &systemIncludes, std::set handledFiles = std::set()); Settings *_settings;