From 08bd1dbe71f1067c43804455f207a74f1c34740a Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 4 Dec 2017 18:05:05 +0200 Subject: [PATCH] Move BOOST_STRINGIZE, BOOST_JOIN to config/helper_macros.hpp; use BOOST_STRINGIZE in BOOST_PRAGMA_MESSAGE --- include/boost/config/detail/suffix.hpp | 19 ++----------- include/boost/config/helper_macros.hpp | 37 +++++++++++++++++++++++++ include/boost/config/pragma_message.hpp | 13 +++++---- test/Jamfile.v2 | 1 + test/helper_macros_test.cpp | 30 ++++++++++++++++++++ 5 files changed, 78 insertions(+), 22 deletions(-) create mode 100644 include/boost/config/helper_macros.hpp create mode 100644 test/helper_macros_test.cpp diff --git a/include/boost/config/detail/suffix.hpp b/include/boost/config/detail/suffix.hpp index caa0b229..4aeac4c7 100644 --- a/include/boost/config/detail/suffix.hpp +++ b/include/boost/config/detail/suffix.hpp @@ -537,25 +537,10 @@ namespace std{ using ::type_info; } // ---------------------------------------------------------------------------// -// // Helper macro BOOST_STRINGIZE: -// Converts the parameter X to a string after macro replacement -// on X has been performed. -// -#define BOOST_STRINGIZE(X) BOOST_DO_STRINGIZE(X) -#define BOOST_DO_STRINGIZE(X) #X - -// // Helper macro BOOST_JOIN: -// The following piece of macro magic joins the two -// arguments together, even when one of the arguments is -// itself a macro (see 16.3.1 in C++ standard). The key -// is that macro expansion of macro arguments does not -// occur in BOOST_DO_JOIN2 but does in BOOST_DO_JOIN. -// -#define BOOST_JOIN( X, Y ) BOOST_DO_JOIN( X, Y ) -#define BOOST_DO_JOIN( X, Y ) BOOST_DO_JOIN2(X,Y) -#define BOOST_DO_JOIN2( X, Y ) X##Y + +#include // // Set some default values for compiler/library/platform names. diff --git a/include/boost/config/helper_macros.hpp b/include/boost/config/helper_macros.hpp new file mode 100644 index 00000000..3e79526d --- /dev/null +++ b/include/boost/config/helper_macros.hpp @@ -0,0 +1,37 @@ +#ifndef BOOST_CONFIG_HELPER_MACROS_HPP_INCLUDED +#define BOOST_CONFIG_HELPER_MACROS_HPP_INCLUDED + +// Copyright 2001 John Maddock. +// Copyright 2017 Peter Dimov. +// +// 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 +// +// BOOST_STRINGIZE(X) +// BOOST_JOIN(X, Y) +// +// Note that this header is C compatible. + +// +// Helper macro BOOST_STRINGIZE: +// Converts the parameter X to a string after macro replacement +// on X has been performed. +// +#define BOOST_STRINGIZE(X) BOOST_DO_STRINGIZE(X) +#define BOOST_DO_STRINGIZE(X) #X + +// +// Helper macro BOOST_JOIN: +// The following piece of macro magic joins the two +// arguments together, even when one of the arguments is +// itself a macro (see 16.3.1 in C++ standard). The key +// is that macro expansion of macro arguments does not +// occur in BOOST_DO_JOIN2 but does in BOOST_DO_JOIN. +// +#define BOOST_JOIN(X, Y) BOOST_DO_JOIN(X, Y) +#define BOOST_DO_JOIN(X, Y) BOOST_DO_JOIN2(X,Y) +#define BOOST_DO_JOIN2(X, Y) X##Y + +#endif // BOOST_CONFIG_HELPER_MACROS_HPP_INCLUDED diff --git a/include/boost/config/pragma_message.hpp b/include/boost/config/pragma_message.hpp index a6292fd0..448ccc0f 100644 --- a/include/boost/config/pragma_message.hpp +++ b/include/boost/config/pragma_message.hpp @@ -9,14 +9,17 @@ // http://www.boost.org/LICENSE_1_0.txt // // BOOST_PRAGMA_MESSAGE("message") +// +// Expands to the equivalent of #pragma message("message") +// +// Note that this header is C compatible. + +#include #if defined(__GNUC__) -#define BOOST_PRAGMA_MESSAGE_IMPL_1(x) _Pragma(#x) -#define BOOST_PRAGMA_MESSAGE(x) BOOST_PRAGMA_MESSAGE_IMPL_1(message(x)) +#define BOOST_PRAGMA_MESSAGE(x) _Pragma(BOOST_STRINGIZE(message(x))) #elif defined(_MSC_VER) -#define BOOST_PRAGMA_MESSAGE_IMPL_2(x, f, ln) __pragma(message(f "(" #ln "): note: " x)) -#define BOOST_PRAGMA_MESSAGE_IMPL_1(x, f, ln) BOOST_PRAGMA_MESSAGE_IMPL_2(x, f, ln) -#define BOOST_PRAGMA_MESSAGE(x) BOOST_PRAGMA_MESSAGE_IMPL_1(x, __FILE__, __LINE__) +#define BOOST_PRAGMA_MESSAGE(x) __pragma(message(__FILE__ "(" BOOST_STRINGIZE(__LINE__) "): note: " x)) #else #define BOOST_PRAGMA_MESSAGE(x) #endif diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 16147352..9f1e4ea4 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -103,6 +103,7 @@ test-suite config [ run cstdint_test2.cpp : : : all gcc:"-Wno-long-long -Wextra" darwin:-Wno-long-long ] [ compile cstdint_include_test.cpp : all gcc:-Wextra ] [ run config_build_check.cpp : : : [ requires int128 cxx11_constexpr cxx11_user_defined_literals ] ] + [ run helper_macros_test.cpp ] [ compile pragma_message_test.cpp ] ; diff --git a/test/helper_macros_test.cpp b/test/helper_macros_test.cpp new file mode 100644 index 00000000..5bbea8dd --- /dev/null +++ b/test/helper_macros_test.cpp @@ -0,0 +1,30 @@ +// Copyright 2017 Peter Dimov. +// +// 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 + +#include +#include + +int main() +{ +#define X pumpkin + + BOOST_TEST_CSTR_EQ( BOOST_STRINGIZE(X), "pumpkin" ); + BOOST_TEST_CSTR_EQ( BOOST_STRINGIZE(__LINE__), "16" ); + +#define Y 2 + + int BOOST_JOIN(X, Y) = 0; + (void)pumpkin2; + + int BOOST_JOIN(X, __LINE__) = 0; + (void)pumpkin23; + + BOOST_TEST_CSTR_EQ( BOOST_STRINGIZE(BOOST_JOIN(X, Y)), "pumpkin2" ); + BOOST_TEST_CSTR_EQ( BOOST_STRINGIZE(BOOST_JOIN(X, __LINE__)), "pumpkin27" ); + + return boost::report_errors(); +}