diff --git a/include/boost/wave/util/cpp_macromap.hpp b/include/boost/wave/util/cpp_macromap.hpp index fad958a3..a56e499d 100644 --- a/include/boost/wave/util/cpp_macromap.hpp +++ b/include/boost/wave/util/cpp_macromap.hpp @@ -1394,6 +1394,8 @@ macromap::rescan_replacement_list(token_type const &curr_token, typename ContainerT::iterator begin_it = replacement_list.begin(); typename ContainerT::iterator end_it = replacement_list.end(); + // An object-like macro's replacement list does not contain the tokens + // following its invocation, which may complete __has_include(...). expand_whole_tokensequence( expanded, begin_it, end_it, expand_operator_defined, expand_operator_has_include); @@ -1643,7 +1645,8 @@ macromap::expand_macro(ContainerT &expanded, rescan_replacement_list( curr_token, macro_def, replacement_list, expanded_list, expand_operator_defined, - expand_operator_has_include, first, last); + expand_operator_has_include && macro_def.is_functionlike, + first, last); ctx.get_hooks().rescanned_macro(ctx.derived(), expanded_list); diff --git a/test/testwave/testfiles/t_2_034.cpp b/test/testwave/testfiles/t_2_034.cpp new file mode 100644 index 00000000..b6bd340e --- /dev/null +++ b/test/testwave/testfiles/t_2_034.cpp @@ -0,0 +1,34 @@ +/*============================================================================= + Boost.Wave: A Standard compliant C++ preprocessor library + http://www.boost.org/ + + Copyright (c) 2026 Martin Medler. Distributed under the Boost + Software License, Version 1.0. (See accompanying file + LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ + +// An object like macro can be used as alias to the special macro __has_include + +//O --c++17 +//O -Werror + +// point system path to this directory +//O -S. + +#define HAS_INCLUDE __has_include +#if HAS_INCLUDE() +#define FOUND_SELF_VIA_ALIAS +#else +#warning has_include could not find this file through an alias +#endif + +//H 10: t_2_034.cpp(18): #define +//H 08: t_2_034.cpp(18): HAS_INCLUDE=__has_include +//H 10: t_2_034.cpp(19): #if +//H 01: t_2_034.cpp(18): HAS_INCLUDE +//H 02: __has_include +//H 03: __has_include +//H 11: t_2_034.cpp(19): #if HAS_INCLUDE(): 1 +//H 10: t_2_034.cpp(20): #define +//H 08: t_2_034.cpp(20): FOUND_SELF_VIA_ALIAS= +//H 10: t_2_034.cpp(21): #else diff --git a/test/testwave/testfiles/t_2_035.cpp b/test/testwave/testfiles/t_2_035.cpp new file mode 100644 index 00000000..1a0cb009 --- /dev/null +++ b/test/testwave/testfiles/t_2_035.cpp @@ -0,0 +1,34 @@ +/*============================================================================= + Boost.Wave: A Standard compliant C++ preprocessor library + http://www.boost.org/ + + Copyright (c) 2026 Martin Medler. Distributed under the Boost + Software License, Version 1.0. (See accompanying file + LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ + +// A function like macro can be used as alias to the special macro __has_include + +//O --c++17 +//O -Werror + +// point system path to this directory +//O -S. + +#define HAS_INCLUDE(x) __has_include(x) +#if HAS_INCLUDE() +#define FOUND_SELF_VIA_ALIAS +#else +#warning has_include could not find this file through an alias +#endif + +//H 10: t_2_035.cpp(18): #define +//H 08: t_2_035.cpp(18): HAS_INCLUDE(x)=__has_include(x) +//H 10: t_2_035.cpp(19): #if +//H 00: t_2_035.cpp(19): HAS_INCLUDE(), [t_2_035.cpp(18): HAS_INCLUDE(x)=__has_include(x)] +//H 02: __has_include() +//H 03: 1 +//H 11: t_2_035.cpp(19): #if HAS_INCLUDE(): 1 +//H 10: t_2_035.cpp(20): #define +//H 08: t_2_035.cpp(20): FOUND_SELF_VIA_ALIAS= +//H 10: t_2_035.cpp(21): #else diff --git a/test/testwave/testfiles/test.cfg b/test/testwave/testfiles/test.cfg index 872f04a5..6952b0c7 100644 --- a/test/testwave/testfiles/test.cfg +++ b/test/testwave/testfiles/test.cfg @@ -86,6 +86,8 @@ t_2_030.cpp t_2_031.cpp t_2_032.cpp t_2_033.cpp +t_2_034.cpp +t_2_035.cpp # # t_3: Predefined macros