diff --git a/include/boost/wave/cpplexer/re2clex/cpp_re2c_lexer.hpp b/include/boost/wave/cpplexer/re2clex/cpp_re2c_lexer.hpp index 12aeecdc..93a8acee 100644 --- a/include/boost/wave/cpplexer/re2clex/cpp_re2c_lexer.hpp +++ b/include/boost/wave/cpplexer/re2clex/cpp_re2c_lexer.hpp @@ -153,9 +153,15 @@ lexer::lexer(IteratorT const &first, scanner.act_in_cpp0x_mode = false; #endif +#if BOOST_WAVE_SUPPORT_CPP1Z != 0 + scanner.act_in_cpp0x_mode = boost::wave::need_cpp1z(language_) + || boost::wave::need_cpp0x(language_); +#endif + #if BOOST_WAVE_SUPPORT_CPP2A != 0 scanner.act_in_cpp2a_mode = boost::wave::need_cpp2a(language_); scanner.act_in_cpp0x_mode = boost::wave::need_cpp2a(language_) + || boost::wave::need_cpp1z(language_) || boost::wave::need_cpp0x(language_); #else scanner.act_in_cpp2a_mode = false; @@ -167,6 +173,7 @@ lexer::lexer(IteratorT const &first, || boost::wave::need_cpp2a(language_); scanner.act_in_cpp0x_mode = boost::wave::need_cpp2b(language_) || boost::wave::need_cpp2a(language_) + || boost::wave::need_cpp1z(language_) || boost::wave::need_cpp0x(language_); #else scanner.act_in_cpp2b_mode = false; diff --git a/include/boost/wave/language_support.hpp b/include/boost/wave/language_support.hpp index 1bbcb31e..bd6f54f1 100644 --- a/include/boost/wave/language_support.hpp +++ b/include/boost/wave/language_support.hpp @@ -121,6 +121,31 @@ need_cpp0x(language_support language) #endif +/////////////////////////////////////////////////////////////////////////////// +// +// need_cpp1z +// +// Extract if the language to support is C++17 +// +/////////////////////////////////////////////////////////////////////////////// +#if BOOST_WAVE_SUPPORT_CPP1Z != 0 + +inline bool +need_cpp1z(language_support language) +{ + return (language & ~support_option_mask) == support_cpp1z; +} + +#else + +inline bool +need_cpp1z(language_support language) +{ + return false; +} + +#endif + /////////////////////////////////////////////////////////////////////////////// // // need_cpp2a diff --git a/include/boost/wave/util/cpp_macromap.hpp b/include/boost/wave/util/cpp_macromap.hpp index 358be7a2..dd659451 100644 --- a/include/boost/wave/util/cpp_macromap.hpp +++ b/include/boost/wave/util/cpp_macromap.hpp @@ -2223,6 +2223,17 @@ macromap::init_predefined_macros(char const *fname, } else #endif +#if BOOST_WAVE_SUPPORT_CPP1Z != 0 + if (boost::wave::need_cpp1z(ctx.get_language())) { + // define C++17 specifics + for (int i = 0; 0 != predef.static_data_cpp1z(i).name; ++i) { + predefined_macros::static_macros const& m = predef.static_data_cpp1z(i); + predefine_macro(current_scope, m.name, + token_type(m.token_id, m.value, pos)); + } + } + else +#endif #if BOOST_WAVE_SUPPORT_CPP2A != 0 if (boost::wave::need_cpp2a(ctx.get_language())) { // define C++20 specifics @@ -2233,6 +2244,17 @@ macromap::init_predefined_macros(char const *fname, } } else +#endif +#if BOOST_WAVE_SUPPORT_CPP2B != 0 + if (boost::wave::need_cpp2b(ctx.get_language())) { + // define C++23 specifics + for (int i = 0; 0 != predef.static_data_cpp2b(i).name; ++i) { + predefined_macros::static_macros const& m = predef.static_data_cpp2b(i); + predefine_macro(current_scope, m.name, + token_type(m.token_id, m.value, pos)); + } + } + else #endif { // define C++ specifics diff --git a/include/boost/wave/util/cpp_macromap_predef.hpp b/include/boost/wave/util/cpp_macromap_predef.hpp index c7af7b52..dd8b0793 100644 --- a/include/boost/wave/util/cpp_macromap_predef.hpp +++ b/include/boost/wave/util/cpp_macromap_predef.hpp @@ -238,6 +238,23 @@ namespace util { } #endif +#if BOOST_WAVE_SUPPORT_CPP1Z != 0 + // C++17 mode + static_macros const& static_data_cpp1z(std::size_t i) const + { + static static_macros data[] = { + { "__STDC__", T_INTLIT, "1" }, + { "__cplusplus", T_INTLIT, "201703L" }, + { "__STDC_VERSION__", T_INTLIT, "199901L" }, + { "__STDC_HOSTED__", T_INTLIT, "0" }, + { "__WAVE_HAS_VARIADICS__", T_INTLIT, "1" }, + { 0, T_EOF, 0 } + }; + BOOST_ASSERT(i < sizeof(data)/sizeof(data[0])); + return data[i]; + } +#endif + #if BOOST_WAVE_SUPPORT_CPP2A != 0 // C++20 mode static_macros const& static_data_cpp2a(std::size_t i) const @@ -255,6 +272,23 @@ namespace util { } #endif +#if BOOST_WAVE_SUPPORT_CPP2B != 0 + // C++23 mode + static_macros const& static_data_cpp2b(std::size_t i) const + { + static static_macros data[] = { + { "__STDC__", T_INTLIT, "1" }, + { "__cplusplus", T_INTLIT, "202302L" }, + { "__STDC_VERSION__", T_INTLIT, "199901L" }, + { "__STDC_HOSTED__", T_INTLIT, "0" }, + { "__WAVE_HAS_VARIADICS__", T_INTLIT, "1" }, + { 0, T_EOF, 0 } + }; + BOOST_ASSERT(i < sizeof(data)/sizeof(data[0])); + return data[i]; + } +#endif + #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0 // C99 mode static_macros const& static_data_c99(std::size_t i) const diff --git a/samples/cpp_tokens/slex/cpp_slex_lexer.hpp b/samples/cpp_tokens/slex/cpp_slex_lexer.hpp index 2e222522..8e369a23 100644 --- a/samples/cpp_tokens/slex/cpp_slex_lexer.hpp +++ b/samples/cpp_tokens/slex/cpp_slex_lexer.hpp @@ -568,7 +568,7 @@ lexer::init_dfa(boost::wave::language_support lang) // if in C++0x mode, add appropriate keywords #if BOOST_WAVE_SUPPORT_CPP0X != 0 - if (boost::wave::need_cpp0x(lang) || boost::wave::need_cpp2a(lang) || boost::wave::need_cpp2b(lang)) { + if (boost::wave::need_cpp0x(lang) || boost::wave::need_cpp1z(lang) || boost::wave::need_cpp2a(lang) || boost::wave::need_cpp2b(lang)) { for (int j = 0; 0 != init_data_cpp0x[j].tokenid; ++j) { this->register_regex(init_data_cpp0x[j].tokenregex, init_data_cpp0x[j].tokenid, init_data_cpp0x[j].tokencb, diff --git a/samples/list_includes/lexertl/lexertl_lexer.hpp b/samples/list_includes/lexertl/lexertl_lexer.hpp index 0a166f4d..c5da2ddb 100644 --- a/samples/list_includes/lexertl/lexertl_lexer.hpp +++ b/samples/list_includes/lexertl/lexertl_lexer.hpp @@ -524,7 +524,7 @@ std::ifstream dfa_in("wave_lexertl_lexer.dfa", std::ios::in|std::ios::binary); // if in C++0x mode, add appropriate keywords #if BOOST_WAVE_SUPPORT_CPP0X != 0 - if (wave::need_cpp0x(lang) || wave::need_cpp2a(lang) || wave::need_cpp2b(lang)) { + if (wave::need_cpp0x(lang) || wave::need_cpp1z(lang) || wave::need_cpp2a(lang) || wave::need_cpp2b(lang)) { for (int j = 0; 0 != init_data_cpp0x[j].tokenid; ++j) { rules.add(init_data_cpp0x[j].tokenregex, init_data_cpp0x[j].tokenid); diff --git a/samples/token_statistics/xlex/xlex_lexer.hpp b/samples/token_statistics/xlex/xlex_lexer.hpp index 8bd1e6bc..3d394855 100644 --- a/samples/token_statistics/xlex/xlex_lexer.hpp +++ b/samples/token_statistics/xlex/xlex_lexer.hpp @@ -506,7 +506,7 @@ lexer::lexer(Iterator const &first, } #if BOOST_WAVE_SUPPORT_CPP0X != 0 - if (boost::wave::need_cpp0x(language) || boost::wave::need_cpp2a(language) || boost::wave::need_cpp2b(language)) { + if (boost::wave::need_cpp0x(language) || boost::wave::need_cpp1z(language) || boost::wave::need_cpp2a(language) || boost::wave::need_cpp2b(language)) { for (int j = 0; 0 != init_data_cpp0x[j].tokenid; ++j) { xlexer.register_regex(init_data_cpp0x[j].tokenregex, init_data_cpp0x[j].tokenid, init_data_cpp[j].tokencb); diff --git a/test/testwave/testfiles/t_3_006.cpp b/test/testwave/testfiles/t_3_006.cpp new file mode 100644 index 00000000..35477be3 --- /dev/null +++ b/test/testwave/testfiles/t_3_006.cpp @@ -0,0 +1,18 @@ +/*============================================================================= + Boost.Wave: A Standard compliant C++ preprocessor library + + 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) +=============================================================================*/ + +// Verify the C++98 values of of the predefined macros + +// C++98 is the default and can't be set explicitly via '--c++XX' in this test framework + +//R #line 14 "t_3_006.cpp" +__cplusplus //R 199711L + +//H 01: (1): __cplusplus +//H 02: 199711L +//H 03: 199711L diff --git a/test/testwave/testfiles/t_3_007.cpp b/test/testwave/testfiles/t_3_007.cpp new file mode 100644 index 00000000..ad7c5e81 --- /dev/null +++ b/test/testwave/testfiles/t_3_007.cpp @@ -0,0 +1,18 @@ +/*============================================================================= + Boost.Wave: A Standard compliant C++ preprocessor library + + 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) +=============================================================================*/ + +// Verify the C++11 values of of the predefined macros + +//O --c++11 + +//R #line 14 "t_3_007.cpp" +__cplusplus //R 201103L + +//H 01: (1): __cplusplus +//H 02: 201103L +//H 03: 201103L diff --git a/test/testwave/testfiles/t_3_009.cpp b/test/testwave/testfiles/t_3_009.cpp new file mode 100644 index 00000000..628cd42c --- /dev/null +++ b/test/testwave/testfiles/t_3_009.cpp @@ -0,0 +1,18 @@ +/*============================================================================= + Boost.Wave: A Standard compliant C++ preprocessor library + + 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) +=============================================================================*/ + +// Verify the C++17 values of of the predefined macros + +//O --c++17 + +//R #line 14 "t_3_009.cpp" +__cplusplus //R 201703L + +//H 01: (1): __cplusplus +//H 02: 201703L +//H 03: 201703L diff --git a/test/testwave/testfiles/t_3_010.cpp b/test/testwave/testfiles/t_3_010.cpp new file mode 100644 index 00000000..b679d932 --- /dev/null +++ b/test/testwave/testfiles/t_3_010.cpp @@ -0,0 +1,18 @@ +/*============================================================================= + Boost.Wave: A Standard compliant C++ preprocessor library + + 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) +=============================================================================*/ + +// Verify the C++20 values of of the predefined macros + +//O --c++20 + +//R #line 14 "t_3_010.cpp" +__cplusplus //R 202002L + +//H 01: (1): __cplusplus +//H 02: 202002L +//H 03: 202002L diff --git a/test/testwave/testfiles/t_3_011.cpp b/test/testwave/testfiles/t_3_011.cpp new file mode 100644 index 00000000..552d92c6 --- /dev/null +++ b/test/testwave/testfiles/t_3_011.cpp @@ -0,0 +1,18 @@ +/*============================================================================= + Boost.Wave: A Standard compliant C++ preprocessor library + + 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) +=============================================================================*/ + +// Verify the C++23 values of of the predefined macros + +//O --c++23 + +//R #line 14 "t_3_011.cpp" +__cplusplus //R 202302L + +//H 01: (1): __cplusplus +//H 02: 202302L +//H 03: 202302L diff --git a/test/testwave/testfiles/test.cfg b/test/testwave/testfiles/test.cfg index a18b1d7d..f0bc20f6 100644 --- a/test/testwave/testfiles/test.cfg +++ b/test/testwave/testfiles/test.cfg @@ -96,6 +96,11 @@ t_3_002.cpp t_3_003.cpp t_3_004.cpp t_3_005.cpp +t_3_006.cpp +t_3_007.cpp +t_3_009.cpp +t_3_010.cpp +t_3_011.cpp # # Preprocessing expressions