diff --git a/simplecpp.cpp b/simplecpp.cpp index 599ffdfe..68db40f3 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -2681,13 +2681,16 @@ static void simplifySizeof(simplecpp::TokenList &expr, const std::map= "201703L"); } +static bool isGnu(const simplecpp::DUI &dui) +{ + return dui.std.rfind("gnu", 0) != std::string::npos; +} static std::string currentDirectoryOSCalc() { const std::size_t size = 4096; @@ -2760,7 +2763,7 @@ static std::string extractRelativePathFromAbsolute(const std::string& absoluteSi 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)) + if (!isCpp17OrLater(dui) && !isGnu(dui)) return; for (simplecpp::Token *tok = expr.front(); tok; tok = tok->next) { @@ -3483,7 +3486,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 = isCpp17OrLater(dui); + const bool hasInclude = isCpp17OrLater(dui) || isGnu(dui); MacroMap macros; for (std::list::const_iterator it = dui.defines.begin(); it != dui.defines.end(); ++it) { const std::string ¯ostr = *it; diff --git a/test.cpp b/test.cpp index cec253b8..edd52f92 100644 --- a/test.cpp +++ b/test.cpp @@ -1563,6 +1563,21 @@ static void has_include_5() ASSERT_EQUALS("", preprocess(code)); } +static void has_include_6() +{ + const char code[] = "#if defined( __has_include)\n" + " #if !__has_include()\n" + " A\n" + " #else\n" + " B\n" + " #endif\n" + "#endif"; + simplecpp::DUI dui; + dui.std = "gnu99"; + ASSERT_EQUALS("\n\nA", preprocess(code, dui)); + ASSERT_EQUALS("", preprocess(code)); +} + static void ifdef1() { const char code[] = "#ifdef A\n" @@ -3123,6 +3138,7 @@ int main(int argc, char **argv) TEST_CASE(has_include_3); TEST_CASE(has_include_4); TEST_CASE(has_include_5); + TEST_CASE(has_include_6); TEST_CASE(ifdef1); TEST_CASE(ifdef2);