@@ -1980,7 +1980,7 @@ namespace simplecpp {
1980
1980
if (tok->next ->str () == " (" )
1981
1981
++paren;
1982
1982
else if (tok->next ->str () == " )" )
1983
- --paren;
1983
+ --paren;
1984
1984
if (paren == 0 )
1985
1985
return tok->next ->next ;
1986
1986
tok = tok->next ;
@@ -2614,11 +2614,20 @@ static void simplifySizeof(simplecpp::TokenList &expr, const std::map<std::strin
2614
2614
}
2615
2615
2616
2616
/* * Evaluate __has_include(file) */
2617
+ static bool isCpp17OrLater (const simplecpp::DUI &dui)
2618
+ {
2619
+ const std::string std_ver = simplecpp::getCppStdString (dui.std );
2620
+ return !std_ver.empty () && (std_ver >= " 201703L" );
2621
+ }
2622
+
2617
2623
static std::string openHeader (std::ifstream &f, const simplecpp::DUI &dui, const std::string &sourcefile, const std::string &header, bool systemheader);
2618
2624
static void simplifyHasInclude (simplecpp::TokenList &expr, const simplecpp::DUI &dui)
2619
2625
{
2626
+ if (!isCpp17OrLater (dui))
2627
+ return ;
2628
+
2620
2629
for (simplecpp::Token *tok = expr.front (); tok; tok = tok->next ) {
2621
- if (tok->str () != " __has_include " )
2630
+ if (tok->str () != HAS_INCLUDE )
2622
2631
continue ;
2623
2632
simplecpp::Token *tok1 = tok->next ;
2624
2633
if (!tok1) {
@@ -3277,7 +3286,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
3277
3286
// 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
3278
3287
std::vector<std::string> dummy;
3279
3288
3280
- const bool hasInclude = (dui. std . size () == 5 && dui. std . compare ( 0 , 3 , " c++ " ) == 0 && dui. std >= " c++17 " );
3289
+ const bool hasInclude = isCpp17OrLater (dui);
3281
3290
MacroMap macros;
3282
3291
for (std::list<std::string>::const_iterator it = dui.defines .begin (); it != dui.defines .end (); ++it) {
3283
3292
const std::string ¯ostr = *it;
0 commit comments