From e040047b6bf538fdcdb80d51f0a444d9d0728661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Fri, 26 Apr 2024 15:42:21 +0200 Subject: [PATCH] improved prerequisite checks for `__has_include` handling (#286) --- simplecpp.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/simplecpp.cpp b/simplecpp.cpp index 2be16c1..47bb78f 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -1980,7 +1980,7 @@ namespace simplecpp { if (tok->next->str() == "(") ++paren; else if (tok->next->str() == ")") - --paren; + --paren; if (paren == 0) return tok->next->next; tok = tok->next; @@ -2614,11 +2614,20 @@ static void simplifySizeof(simplecpp::TokenList &expr, const std::map= "201703L"); +} + static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const std::string &sourcefile, const std::string &header, bool systemheader); static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI &dui) { + if (!isCpp17OrLater(dui)) + return; + for (simplecpp::Token *tok = expr.front(); tok; tok = tok->next) { - if (tok->str() != "__has_include") + if (tok->str() != HAS_INCLUDE) continue; simplecpp::Token *tok1 = tok->next; if (!tok1) { @@ -3277,7 +3286,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL // use a dummy vector for the macros because as this is not part of the file and would add an empty entry - e.g. /usr/include/poll.h std::vector dummy; - const bool hasInclude = (dui.std.size() == 5 && dui.std.compare(0,3,"c++") == 0 && dui.std >= "c++17"); + const bool hasInclude = isCpp17OrLater(dui); MacroMap macros; for (std::list::const_iterator it = dui.defines.begin(); it != dui.defines.end(); ++it) { const std::string ¯ostr = *it;