]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
AC_PROG_CXX now tries C++23, C++20, C++17, C++14
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 26 May 2024 16:20:56 +0000 (09:20 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 26 May 2024 16:24:02 +0000 (09:24 -0700)
The recent glitch with C++11 underscores the fact that it’s
long past time for Autoconf to catch up with the C++ standards.
Add simple tests for each iteration of the C++ standard.
They can be improved later as needed.  When testing for these
newer standards, do not also test for features required by earlier
standards, as this isn’t all that helpful, leads to an O(N**2)
growth of ‘configure’, and can result in problems such as the
C++11 vs C++20 bug recently fixed.
* lib/autoconf/c.m4 (_AC_CXX_CXX14_TEST_PROGRAM)
(_AC_CXX_CXX17_TEST_PROGRAM, _AC_CXX_CXX20_TEST_PROGRAM)
(_AC_CXX_CXX23_TEST_PROGRAM, _AC_CXX_CXX14_OPTIONS)
(_AC_CXX_CXX17_OPTIONS, _AC_CXX_CXX20_OPTIONS)
(_AC_CXX_CXX23_OPTIONS): New macros.
(_AC_C_C23_TEST_PROGRAM, _AC_C_C23_OPTIONS): New macros.
(_AC_PROG_CC_STDC_EDITION): Try C23 first.
(_AC_PROG_CXX_STDCXX_EDITION): Use them.

NEWS
doc/autoconf.texi
lib/autoconf/c.m4

diff --git a/NEWS b/NEWS
index 20dbc1734d983849fd0be54e39db8c2eb60362d5..4ba8f3feaec4c0218029446d09b91313d90cfc05 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,10 @@ GNU Autoconf NEWS - User visible changes.
   C11 and later.  Programs can use AC_C_VARARRAYS and __STDC_NO_VLA__
   to use VLAs if available.
 
+*** AC_PROG_CXX now prefers C++23, C++20, C++17, C++14 if available.
+  Older code may need to be updated, as some older features of C++ are
+  removed in later standards.
+
 ** Notable bug fixes
 
 *** AC_PROG_CXX no longer rejects C++20 compilers
index b50d0a2b7a21283d6ab2538262b458e76f84af1c..37e0ae0171e48e43e450dc974135ac104353c0ad 100644 (file)
@@ -7825,11 +7825,12 @@ person building the package.  @xref{Preset Output Variables}.)
 If necessary, options are added to @code{CXX} to enable support for
 ISO Standard C++ features with extensions, preferring the newest edition
 of the C++ standard that is supported.  Currently the newest edition
-Autoconf knows how to detect support for is C++11.  After calling
+Autoconf knows how to detect support for is C++23.  After calling
 this macro, you can check whether the C++ compiler has been set to
 accept standard C++ by inspecting the shell variable @code{ac_prog_cxx_stdcxx}.
-Its value will be @samp{cxx11} or @samp{cxx98}, respectively,
-if the C++ compiler has been set to use the 2011 or 1990 edition of the
+Its value will be @samp{cxx23}, @samp{cxx20}, @samp{cxx17},
+@samp{cxx14}, @samp{cxx11} or @samp{cxx98},
+if the C++ compiler has been set to use the corresponding edition of the
 C++ standard, and @samp{no} if the compiler does not support compiling
 standard C++ at all.
 
@@ -21714,6 +21715,8 @@ standard.  K&R C compilers are no longer of practical interest, though,
 and Autoconf assumes at least C89, the first C standard,
 which is sometimes called ``C90'' due to a delay in standardization.
 C has since gone through the standards C99, C11, C17, and C23, and
+C++ has evolved in a similar way, with the standards
+C++98, C++11, C++14, C++17, C++20, and C++23.
 Autoconf is compatible with all these standards.
 
 Program portability is a huge topic, and this section can only briefly
index 150bb8146ece3650555c95c28a5e17302d61adf9..a0a2b487e23144d7a4cf9c2e4eeb4dabab316a19 100644 (file)
@@ -2802,6 +2802,68 @@ main (int argc, char **argv)
 "
 ]])])
 
+AC_DEFUN([_AC_CXX_CXX14_TEST_PROGRAM],
+[m4_divert_text([INIT_PREPARE],
+[[ac_cxx_conftest_cxx14_program='
+#if __cplusplus < 201402
+# error "Compiler does not advertise C++14 conformance"
+#endif
+
+int
+main ()
+{
+  auto floating_point_literal_with_single_quotes = 0.123'\''456;
+}
+'
+]])])
+
+AC_DEFUN([_AC_CXX_CXX17_TEST_PROGRAM],
+[m4_divert_text([INIT_PREPARE],
+[[ac_cxx_conftest_cxx17_program='
+#if __cplusplus < 201707
+# error "Compiler does not advertise C++17 conformance"
+#endif
+
+int
+main ()
+{
+  auto u8_expression_with_u8_character_literals = u8'\''x'\'' == u8'\''x'\'';
+}
+'
+]])])
+
+AC_DEFUN([_AC_CXX_CXX20_TEST_PROGRAM],
+[m4_divert_text([INIT_PREPARE],
+[[ac_cxx_conftest_cxx20_program='
+#if __cplusplus < 202002
+# error "Compiler does not advertise C++20 conformance"
+#endif
+
+#include <compare>
+
+int
+main ()
+{
+  auto expression_with_three_way_comparison = 1 <=> 2;
+}
+'
+]])])
+
+AC_DEFUN([_AC_CXX_CXX23_TEST_PROGRAM],
+[m4_divert_text([INIT_PREPARE],
+[[ac_cxx_conftest_cxx23_program='
+#if __cplusplus < 202302
+# error "Compiler does not advertise C++23 conformance"
+#endif
+
+int
+main ()
+{
+  auto expression_with_signed_size_literal = -1z < 0;
+}
+'
+]])])
+
 # _AC_CXX_CXX98_OPTIONS
 # ---------------------
 # Whitespace-separated list of options that might put the C++ compiler
@@ -2850,6 +2912,13 @@ m4_define([_AC_CXX_CXX11_OPTIONS], [
     -AA
 ])
 
+# Similarly for C++14, C++17, C++20, C++23,
+# where -std=gnu++XX should be good enough.
+m4_define([_AC_CXX_CXX14_OPTIONS], [-std=gnu++14])
+m4_define([_AC_CXX_CXX17_OPTIONS], [-std=gnu++17])
+m4_define([_AC_CXX_CXX20_OPTIONS], [-std=gnu++20])
+m4_define([_AC_CXX_CXX23_OPTIONS], [-std=gnu++23])
+
 # _AC_PROG_CXX_STDCXX_EDITION_TRY(EDITION)
 # ----------------------------------------
 # Subroutine of _AC_PROG_CXX_STDCXX_EDITION.  Not to be called directly.
@@ -2910,4 +2979,4 @@ AS_IF([test "x$ac_cv_prog_cxx_cxx$1" = xno],
 # variable ac_prog_cxx_stdcxx to indicate the edition.
 AC_DEFUN([_AC_PROG_CXX_STDCXX_EDITION],
 [ac_prog_cxx_stdcxx=no
-m4_map([_AC_PROG_CXX_STDCXX_EDITION_TRY], [[11], [98]])])
+m4_map([_AC_PROG_CXX_STDCXX_EDITION_TRY], [23, 20, 17, 14, 11, 98])])