@@ -2950,39 +2950,35 @@ define a module of the same name in multiple source files.
29502950@node Using C++ code
29512951@subsection Using C++ code
29522952
2953- @R{} can be built without a C++ compiler although one is available (but
2954- not necessarily installed) on all known @R{} platforms.
2955- standard (`C++11'). A minor update@footnote{Some changes are linked
2956- from
2957- @uref{https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations}:
2958- there were also additional deprecations.} (`C++14') was published in
2959- December 2014 and was used by default as from @R{} 4.1.0 if supported.
2960- Further revisions `C++17' (in December 2017), `C++20' (with many new
2961- features in December 2020) and `C++23' (in October 2024) have been
2962- published since. The next revision, `C++26', is expected in 2026/7 and
2963- several compilers already have considerable support for the current
2964- draft.
2965-
2966- The support in @R{} for these standards has varied over the years: this
2967- version of the manual only describes @R{} 4.3.0 and later. For details
2968- of earlier versions, see the corresponding section in their manuals.
2953+ A new C++ standard has been published every three years since 2011.
2954+ C++26 was feature-frozen in October 2025 and is expected to be published
2955+ in late 2026.
29692956
29702957The default standard for compiling @R{} packages was changed to C++17 in
2971- @R{} 4.3.0 if supported, and from @R{} 4.4.0 only a C++17 compiler will
2972- be selected as the default C++ compiler.
2958+ @R{} 4.4.0: only a C++17 compiler will be selected as the default C++
2959+ compiler. Such a compiler is available (but not necessarily installed)
2960+ on all known @R{} platforms. It is intended that C++20 will become the
2961+ default (`where available') in @R{} 4.6.0: it has been supported on all
2962+ known platforms since at least 2021.
2963+ @c The last was Intel compilers.
2964+
2965+ @R{} has long allowed packages to request a C++ standard: recent
2966+ releases support C++17, C++20, C++23 and C++26 (if a suitable compiler
2967+ is available when @R{} was built): C++11 and C++14 were supported prior
2968+ to @R{} 4.6.0.
29732969
29742970What standard a C++ compiler aims to support can be hard to determine:
29752971the value@footnote{Values @code{201103L}, @code{201402L}, @code{201703L}
29762972and @code{202002L} are most commonly used for C++11, C++14, C++17 and
29772973C++20 respectively, but some compilers set @code{1L}. For C++23 all that
29782974can currently be assumed is a value greater than that for C++20: for
2979- example @command{g++} 12 uses @code{202100L} and @command{clang++} (@I{LLVM}
2980- 15, Apple 14) uses @code{202101L}.} of @code{__cplusplus} may help but
2981- some compilers use it to denote a standard which is partially supported
2982- and some the latest standard which is (almost) fully supported. On a
2983- Unix-alike @command{configure} will try to identify a compiler and flags
2984- for each of the standards: this relies heavily on the reported values of
2985- @code{__cplusplus}.
2975+ example @command{g++} 12 uses @code{202100L} and @command{clang++}
2976+ (@I{LLVM} 15, Apple 14) uses @code{202101L}.} of @code{__cplusplus} may
2977+ help but some compilers use it to denote a standard which is partially
2978+ supported and some the latest standard which is (almost) fully
2979+ supported. On a Unix-alike @R{}'s @ command{configure} will try to
2980+ identify a compiler and flags for each of the supported standards: this
2981+ relies heavily on the reported values of @code{__cplusplus}.
29862982
29872983@c Apple clang 14 defaults to C++98 (even 16)
29882984@c @I{LLVM} clang 14, 15 default to C++14, 16-20 to C++17
@@ -2998,10 +2994,10 @@ C++ standards have deprecated and later removed features (such as
29982994headers, types and functions). Be aware that some current compilers
29992995still accept removed features in C++17 mode, such as
30002996@code{std::unary_function} (deprecated in C++11, removed in C++17) or
3001- removed in C++20 (such as @code{std::uncaught_exception}). And some
3002- compilers in use are far from current, notably those used for
3003- @acronym{CRAN} macOS builds. The Wikipedia pages for the various
3004- standards list deprecated and removed (and undeprecated) features.
2997+ removed in C++20 (such as @code{std::uncaught_exception}), and most do
2998+ not warn on the use of deprecated features. (And some compilers in use
2999+ are far from current.) The Wikipedia pages for the various standards
3000+ list deprecated and removed (and also undeprecated) features.
30053001
30063002For maximal portability a package should specify the standard it
30073003requires for code in its @file{src} directory by including something
@@ -3018,6 +3014,9 @@ If it has a @file{Makevars} file (or @file{Makevars.win} or
30183014CXX_STD = CXX23
30193015@end example
30203016
3017+ C++20, C++23 and C++26 (from @R{} 4.5.0) can be specified in an
3018+ analogous way.
3019+
30213020Code needing C++20 or later features can check for their presence @emph{via}
30223021`SD-6 feature tests'@footnote{See
30233022@uref{https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations}
@@ -3026,26 +3025,22 @@ or
30263025
30273026@c Ubuntu LTS releases now have 10 years of support even if announced
30283027@c with 8 years.
3029- @c Ubuntu 14.04LTS (4.8, ESM support extended until 2024-04)
30303028@c Ubuntu 16.04LTS (5.3, ESM support extended until 2026-04)
30313029@c Ubuntu 18.04LTS (7.5, on ESM support until 2028-04)
30323030@c Ubuntu 20.04LTS (9.4, 10.5 available)
30333031@c Ubuntu 22.04LTS (11.x)
3034- @c Centos 7 (4.8.5, ESM support until 2024-06)
30353032@c https://access.redhat.com/solutions/19458
30363033@c RHEL 7 (4.8, goes to 'extended life cycle' 2024-07 to 2028-06-30)
30373034@c RHEL 8 (8.x, 9.x available. full support 2024-05 + 8 more years)
30383035@c RHEL 9 (11.x available, full support 2027-05 + 8 more years)
30393036
3040- C++20, C++23 and C++26 (from @R{} 4.5.0) can be specified in an
3041- analogous way.
3042-
3043- Note that C++17 or later `support' does not mean complete support: use
3037+ Note that `support' for a standard does not mean complete support: use
30443038feature tests as well as resources such as
30453039@uref{https://en.cppreference.com/w/cpp/compiler_support.html},
30463040@uref{https://gcc.gnu.org/projects/cxx-status.html} and
30473041@uref{https://clang.llvm.org/cxx_status.html} to see if the features you
3048- want to use are widely implemented.
3042+ want to use are widely implemented. (In particular, C++20 modules were
3043+ not.)
30493044
30503045Attempts to specify an unknown C++ standard are silently ignored: recent
30513046versions of @R{} throw an error for C++98 and for known standards for
@@ -3076,7 +3071,8 @@ CXXFLAGS=`"$@{R_HOME@}/bin/R" CMD config CXXFLAGS`
30763071AC_LANG(C++)
30773072@end example
30783073@noindent
3079- if no standard was specified.
3074+ if no standard was specified. The script needs to check that @code{CXX}
3075+ is not empty.
30803076
30813077If you want to compile C++ code in a subdirectory, make sure you pass
30823078down the macros to specify the appropriate compiler, e.g.@: in
0 commit comments