Re: configure adds -std=gnu++11 to CXX variable
Paul Eggert <[email protected]> Sun, 26 May 2024 09:31:53 -0700
| Newsgroups | gmane.comp.sysutils.autoconf.general |
|---|---|
| Organization | UCLA Computer Science Department |
| Message-ID | <[email protected]> |
Thanks for the patch. I installed something like it (see first attached patch; sorry, I misspelled "C++11" as "C11" in the commit message). This underscores the fact that Autoconf really, really should test for later C++ standards, as documented. I installed the second attached patch to get the ball rolling on this. As Zack mentioned, developers and builders need ways to say things like "I want C++20 even if the compiler supports C++23". The simplest way to do that would be to document the existing mechanism, which relies on setting the appropriate cache variables. I volunteer to do that unless someone else wants to do something fancier (which would make my work unnecessary and possibly even counterproductive). I am not a C++ expert and so used only very simple test programs in the second patch. Improvements from C++ experts would be welcome. The idea would be to test for features that programs actually need, not to test for every little minor detail. Obviously there are judgment calls.
0001-Port-C11-test-to-C-20.patch
(text/x-patch, 1.5 KB)
From e6c9cb69c8c0a4ef9ce0538d7b4106dad3d7ad47 Mon Sep 17 00:00:00 2001 From: Paul Eggert <[email protected]> Date: Sun, 26 May 2024 07:04:19 -0700 Subject: [PATCH 1/2] Port C11 test to C++20 Trivial fix suggested by Peter Johansson in: https://lists.gnu.org/r/autoconf/2024-05/msg00004.html * lib/autoconf/c.m4 (_AC_CXX_CXX11_TEST_MAIN): Do not test assigning u8"..." to char const *, as this runs afoul of C++20. --- NEWS | 5 +++++ lib/autoconf/c.m4 | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index be7cb8ca..20dbc173 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,11 @@ GNU Autoconf NEWS - User visible changes. C11 and later. Programs can use AC_C_VARARRAYS and __STDC_NO_VLA__ to use VLAs if available. +** Notable bug fixes + +*** AC_PROG_CXX no longer rejects C++20 compilers +merely because C++20 is not upward-compatible with C++11. + * Noteworthy changes in release 2.72 (2023-12-22) [release] ** Backward incompatibilities diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4 index 89f6a608..150bb814 100644 --- a/lib/autoconf/c.m4 +++ b/lib/autoconf/c.m4 @@ -2758,8 +2758,7 @@ ac_cxx_conftest_cxx11_main=' test_template<::test_template<int>> v(test_template<int>(12)); } { - // Unicode literals - char const *utf8 = u8"UTF-8 string \u2500"; + // Unicode literals. Do not test u8"..." as C++20 would reject it. char16_t const *utf16 = u"UTF-8 string \u2500"; char32_t const *utf32 = U"UTF-32 string \u2500"; } -- 2.43.0
0002-AC_PROG_CXX-now-tries-C-23-C-20-C-17-C-14.patch
(text/x-patch, 5.7 KB)
From f6522328c71a62e3d182def319167ac15c8feaa5 Mon Sep 17 00:00:00 2001 From: Paul Eggert <[email protected]> Date: Sun, 26 May 2024 09:20:56 -0700 Subject: [PATCH 2/2] AC_PROG_CXX now tries C++23, C++20, C++17, C++14 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 | 4 +++ doc/autoconf.texi | 9 ++++-- lib/autoconf/c.m4 | 71 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 80 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 20dbc173..4ba8f3fe 100644 --- 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 diff --git a/doc/autoconf.texi b/doc/autoconf.texi index b50d0a2b..37e0ae01 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -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 diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4 index 150bb814..a0a2b487 100644 --- a/lib/autoconf/c.m4 +++ b/lib/autoconf/c.m4 @@ -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])]) -- 2.43.0