Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions include/boost/wave/util/cpp_macromap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,13 +742,24 @@ macromap<ContextT>::expand_tokensequence_worker(
{
// try to replace this identifier as a macro
if (expand_operator_defined && (*first).get_value() == "defined") {
if (T_EOI == impl::next_token<unput_queue_iterator<IteratorT, token_type, ContainerT>>::peek(first, last)) {
// no further tokens are available - likely because someone defined an object-like macro that expands to "defined"
// do what expand_macro would do in this situation:
act_token = *first++;
return act_token;
}
// resolve operator defined()
return resolve_defined(first, last, pending);
}
#if BOOST_WAVE_SUPPORT_HAS_INCLUDE != 0
else if (boost::wave::need_has_include(ctx.get_language()) &&
expand_operator_has_include &&
(*first).get_value() == "__has_include") {
if (T_LEFTPAREN != impl::next_token<unput_queue_iterator<IteratorT, token_type, ContainerT>>::peek(first, last)) {
// may be an object-like macro that expands to "__has_include"
act_token = *first++;
return act_token;
}
// resolve operator __has_include()
return resolve_has_include(first, last, pending);
}
Expand Down
67 changes: 67 additions & 0 deletions test/testwave/testfiles/t_2_024.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,70 @@
//H 10: t_2_024.cpp(80): #else
//H 10: t_2_024.cpp(83): #endif

// test object-like macro defined as __has_include
#define HI __has_include
#if HI(<t_2_024.cpp>)
#define FOUND_SELF_VIA_SYSTEM_PATH_AND_OBJLIKE
#else
#warning could not find this file via system path when expanded via an object-like macro
#endif

//H 10: t_2_024.cpp(97): #define
//H 08: t_2_024.cpp(97): HI=__has_include
//H 10: t_2_024.cpp(98): #if
//H 01: t_2_024.cpp(97): HI
//H 02: __has_include
//H 03: __has_include
//H 11: t_2_024.cpp(98): #if HI(<t_2_024.cpp>): 1
//H 10: t_2_024.cpp(99): #define
//H 08: t_2_024.cpp(99): FOUND_SELF_VIA_SYSTEM_PATH_AND_OBJLIKE=
//H 10: t_2_024.cpp(100): #else

#if HI("made_up_name_dont_create.hpp")
#warning this made up file should not exist but has_include thinks otherwise
#else
// the good case
#endif

//H 10: t_2_024.cpp(115): #if
//H 01: t_2_024.cpp(97): HI
//H 02: __has_include
//H 03: __has_include
//H 11: t_2_024.cpp(115): #if HI("made_up_name_dont_create.hpp"): 0
//H 10: t_2_024.cpp(119): #endif

// test function-like macro that wraps __has_include
#define HIF(x) __has_include(x)
#if HIF(<t_2_024.cpp>)
#define FOUND_SELF_VIA_SYSTEM_PATH_AND_FUNCLIKE
#else
#warning could not find this file via system path when expanded via a function-like macro
#endif

//H 10: t_2_024.cpp(129): #define
//H 08: t_2_024.cpp(129): HIF(x)=__has_include(x)
//H 10: t_2_024.cpp(130): #if
//H 00: t_2_024.cpp(130): HIF(<t_2_024.cpp>), [t_2_024.cpp(129): HIF(x)=__has_include(x)]
//H 02: __has_include(<t_2_024.cpp>)
//H 03: 1
//H 11: t_2_024.cpp(130): #if HIF(<t_2_024.cpp>): 1
//H 10: t_2_024.cpp(131): #define
//H 08: t_2_024.cpp(131): FOUND_SELF_VIA_SYSTEM_PATH_AND_FUNCLIKE=
//H 10: t_2_024.cpp(132): #else

#define HIF(x) __has_include(x)
#if HIF("made_up_name_dont_create.hpp")
#warning found a file that should not exists but has_include thinks otherwise via function-like expansion
#else
#define DID_NOT_FIND_SELF_VIA_SYSTEM_PATH_AND_FUNCLIKE
#endif

//H 10: t_2_024.cpp(147): #define
//H 10: t_2_024.cpp(148): #if
//H 00: t_2_024.cpp(148): HIF("made_up_name_dont_create.hpp"), [t_2_024.cpp(129): HIF(x)=__has_include(x)]
//H 02: __has_include("made_up_name_dont_create.hpp")
//H 03: 0
//H 11: t_2_024.cpp(148): #if HIF("made_up_name_dont_create.hpp"): 0
//H 10: t_2_024.cpp(151): #define
//H 08: t_2_024.cpp(151): DID_NOT_FIND_SELF_VIA_SYSTEM_PATH_AND_FUNCLIKE=
//H 10: t_2_024.cpp(152): #endif
22 changes: 22 additions & 0 deletions test/testwave/testfiles/t_2_025.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,25 @@
//H 10: t_2_025.cpp(60): #define
//H 08: t_2_025.cpp(60): FOUND_ABRACKET=
//H 10: t_2_025.cpp(61): #else

// try an object-like macro that expands to __has_include
#define HI __has_include
#if HI(FOO(BAR))
#define FOUND_DQUOTE_WITH_OBJLIKE
#else
#warning has_include could not find this file using quotes from object-like macro
#endif

//H 10: t_2_025.cpp(79): #define
//H 08: t_2_025.cpp(79): HI=__has_include
//H 10: t_2_025.cpp(80): #if
//H 01: t_2_025.cpp(79): HI
//H 02: __has_include
//H 03: __has_include
//H 00: t_2_025.cpp(80): FOO(BAR), [t_2_025.cpp(35): FOO(X)="t_2_025.cpp"]
//H 02: "t_2_025.cpp"
//H 03: "t_2_025.cpp"
//H 11: t_2_025.cpp(80): #if HI(FOO(BAR)): 1
//H 10: t_2_025.cpp(81): #define
//H 08: t_2_025.cpp(81): FOUND_DQUOTE_WITH_OBJLIKE=
//H 10: t_2_025.cpp(82): #else
37 changes: 37 additions & 0 deletions test/testwave/testfiles/t_2_034.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*=============================================================================
Boost.Wave: A Standard compliant C++ preprocessor library
http://www.boost.org/

Copyright (c) 2026 Jeff Trull. 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)
=============================================================================*/

// Verify that an object-like macro that expands to defined works as expected

#define FOO
#define DEFND defined

#if DEFND FOO
// this is good
#else
#warning defined expansion w/o parenthesis fails
#endif

#if !DEFND FOO
#warning negated defined expansion w/o parenthesis fails
#else
// this is good
#endif

#if DEFND(FOO)
// this is good
#else
#warning defined expansion with parenthesis fails
#endif

#if !DEFND(FOO)
#warning negated defined expansion with parenthesis fails
#else
// this is good
#endif
1 change: 1 addition & 0 deletions test/testwave/testfiles/test.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ t_2_030.cpp
t_2_031.cpp
t_2_032.cpp
t_2_033.cpp
t_2_034.cpp

#
# t_3: Predefined macros
Expand Down
Loading