Re: configure adds -std=gnu++11 to CXX variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2024-05-28 08:02, Jakub Jelinek wrote:
even for C GCC updates the default

True, but C seems to be different, in that using a later-than-default -std=whatever is more likely to help than hurt, because the C standardization folks are more careful about compatibility. That's what I've been experiencing with -std=gnu23, for example, even though C23 has lots of changes from C17.


> Autoconf should go back to its 2.69 behavior and not mess with the C++
> version as that's more likely to hurt than help.

Yes.

OK, thanks, I installed the attached.
From 056518b94ecd487bcbefdb69046b3f52c4168222 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@xxxxxxxxxxx>
Date: Tue, 28 May 2024 09:31:11 -0700
Subject: [PATCH] AC_PROG_CXX no longer adjusts C++ language version

* lib/autoconf/c.m4 (_AC_CXX_CXX98_TEST_GLOBALS)
(_AC_CXX_CXX98_TEST_MAIN, _AC_CXX_CXX11_TEST_GLOBALS)
(_AC_CXX_CXX11_TEST_MAIN, _AC_CXX_CXX98_TEST_PROGRAM)
(_AC_CXX_CXX11_TEST_PROGRAM, _AC_CXX_CXX14_TEST_PROGRAM)
(_AC_CXX_CXX17_TEST_PROGRAM, _AC_CXX_CXX20_TEST_PROGRAM)
(_AC_CXX_CXX23_TEST_PROGRAM, _AC_CXX_CXX98_OPTIONS)
(_AC_CXX_CXX11_OPTIONS, _AC_CXX_CXX14_OPTIONS)
(_AC_CXX_CXX17_OPTIONS, _AC_CXX_CXX20_OPTIONS)
(_AC_CXX_CXX23_OPTIONS, _AC_PROG_CXX_STDCXX_EDITION_TRY)
(_AC_PROG_CXX_STDCXX_EDITION_TRY): Remove.  All uses removed.
---
 NEWS              |  13 +-
 doc/autoconf.texi |  29 ---
 lib/autoconf/c.m4 | 439 ----------------------------------------------
 3 files changed, 5 insertions(+), 476 deletions(-)

diff --git a/NEWS b/NEWS
index 4ba8f3fe..521bbd3a 100644
--- a/NEWS
+++ b/NEWS
@@ -16,14 +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.
 
-*** 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
-merely because C++20 is not upward-compatible with C++11.
+*** AC_PROG_CXX no longer attempts to switch to C++98 or C++11.
+  Instead, it uses the compiler's default, which you can override
+  by configuring with something like CXX='g++ -std=gnu++11'.
+  This reverts to Autoconf 2.69 behavior, and also fixes a bug where
+  AC_PROG_CXX rejected C++20 compilers.
 
 * Noteworthy changes in release 2.72 (2023-12-22) [release]
 
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 37e0ae01..c36eefdb 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -7821,33 +7821,6 @@ where @var{options} are the appropriate set of options to use by
 default.  (It is important to use this construct rather than a normal
 assignment, so that @code{CXXFLAGS} can still be overridden by the
 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++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{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.
-
-The tests for standard conformance are not comprehensive.  They test
-the value of @code{__cplusplus} and a representative sample of the
-language features added in each version of the C++ standard.  They
-do not test the C++ standard library, because this can be extremely
-slow, and because the C++ compiler might be generating code for a
-``freestanding environment'' (in which most of the C++ standard library
-is optional).  If you need to know whether a particular C++ standard
-header exists, use @code{AC_CHECK_HEADER}.
-
-None of the options that may be added to @code{CXX} by this macro
-enable @emph{strict} conformance to the C++ standard.  In particular,
-system-specific extensions are not disabled.  (For example, for GNU
-C++, the @option{-std=gnu++@var{nn}} options may be used, but not the
-@option{-std=c++@var{nn}} options.)
 @end defmac
 
 @defmac AC_PROG_CXXCPP
@@ -21715,8 +21688,6 @@ 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 a0a2b487..456a6ba7 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -719,7 +719,6 @@ else
   GXX=
 fi
 _AC_PROG_CXX_G
-_AC_PROG_CXX_STDCXX_EDITION
 AC_LANG_POP(C++)dnl
 ])# AC_PROG_CXX
 
@@ -2542,441 +2541,3 @@ AC_DEFUN([_AC_OPENMP_SAFE_WD],
     [AC@&t@_OPENMP clobbers files named 'mp' and 'penmp'.
      Aborting configure because one of these files already exists.]))
 fi])
-
-
-
-# ---------------------------------- #
-# 4b. C++ compiler characteristics.  #
-# ---------------------------------- #
-
-# See the long comment at the beginning of section 4a for rationale
-# for these macros, and constraints on how the test programs should
-# be written.
-#
-# The C++98 freestanding headers are:
-#     <cstdarg> <cstddef> <cstdlib> <exception> <limits> <new> <typeinfo>
-# C++11 adds:
-#    <atomic> <cfloat> <ciso646> <climits> <cstdalign> <cstdbool>
-#    <cstdint> <initializer_list> <type_traits>
-#
-# No other headers can safely be included.  Therefore, almost no C++
-# standard library features are tested for.  Use AC_CHECK_HEADER, etc.
-# if you need that.
-
-AC_DEFUN([_AC_CXX_CXX98_TEST_GLOBALS],
-[m4_divert_text([INIT_PREPARE],
-[[# Test code for whether the C++ compiler supports C++98 (global declarations)
-ac_cxx_conftest_cxx98_globals='
-// Does the compiler advertise C++98 conformance?
-#if !defined __cplusplus || __cplusplus < 199711L
-# error "Compiler does not advertise C++98 conformance"
-#endif
-
-// These inclusions are to reject old compilers that
-// lack the unsuffixed header files.
-#include <cstdlib>
-#include <exception>
-
-// <cassert> and <cstring> are *not* freestanding headers in C++98.
-extern void assert (int);
-namespace std {
-  extern int strcmp (const char *, const char *);
-}
-
-// Namespaces, exceptions, and templates were all added after "C++ 2.0".
-using std::exception;
-using std::strcmp;
-
-namespace {
-
-void test_exception_syntax()
-{
-  try {
-    throw "test";
-  } catch (const char *s) {
-    // Extra parentheses suppress a warning when building autoconf itself,
-    // due to lint rules shared with more typical C programs.
-    assert (!(strcmp) (s, "test"));
-  }
-}
-
-template <typename T> struct test_template
-{
-  T const val;
-  explicit test_template(T t) : val(t) {}
-  template <typename U> T add(U u) { return static_cast<T>(u) + val; }
-};
-
-} // anonymous namespace
-'
-]])])
-
-AC_DEFUN([_AC_CXX_CXX98_TEST_MAIN],
-[m4_divert_text([INIT_PREPARE],
-[[# Test code for whether the C++ compiler supports C++98 (body of main)
-ac_cxx_conftest_cxx98_main='
-  assert (argc);
-  assert (! argv[0]);
-{
-  test_exception_syntax ();
-  test_template<double> tt (2.0);
-  assert (tt.add (4) == 6.0);
-  assert (true && !false);
-}
-'
-]])])
-
-AC_DEFUN([_AC_CXX_CXX11_TEST_GLOBALS],
-[m4_divert_text([INIT_PREPARE],
-[[# Test code for whether the C++ compiler supports C++11 (global declarations)
-ac_cxx_conftest_cxx11_globals='
-// Does the compiler advertise C++ 2011 conformance?
-#if !defined __cplusplus || __cplusplus < 201103L
-# error "Compiler does not advertise C++11 conformance"
-#endif
-
-namespace cxx11test
-{
-  constexpr int get_val() { return 20; }
-
-  struct testinit
-  {
-    int i;
-    double d;
-  };
-
-  class delegate
-  {
-  public:
-    delegate(int n) : n(n) {}
-    delegate(): delegate(2354) {}
-
-    virtual int getval() { return this->n; };
-  protected:
-    int n;
-  };
-
-  class overridden : public delegate
-  {
-  public:
-    overridden(int n): delegate(n) {}
-    virtual int getval() override final { return this->n * 2; }
-  };
-
-  class nocopy
-  {
-  public:
-    nocopy(int i): i(i) {}
-    nocopy() = default;
-    nocopy(const nocopy&) = delete;
-    nocopy & operator=(const nocopy&) = delete;
-  private:
-    int i;
-  };
-
-  // for testing lambda expressions
-  template <typename Ret, typename Fn> Ret eval(Fn f, Ret v)
-  {
-    return f(v);
-  }
-
-  // for testing variadic templates and trailing return types
-  template <typename V> auto sum(V first) -> V
-  {
-    return first;
-  }
-  template <typename V, typename... Args> auto sum(V first, Args... rest) -> V
-  {
-    return first + sum(rest...);
-  }
-}
-'
-]])])
-
-AC_DEFUN([_AC_CXX_CXX11_TEST_MAIN],
-[m4_divert_text([INIT_PREPARE],
-[[# Test code for whether the C++ compiler supports C++11 (body of main)
-ac_cxx_conftest_cxx11_main='
-{
-  // Test auto and decltype
-  auto a1 = 6538;
-  auto a2 = 48573953.4;
-  auto a3 = "String literal";
-
-  int total = 0;
-  for (auto i = a3; *i; ++i) { total += *i; }
-
-  decltype(a2) a4 = 34895.034;
-}
-{
-  // Test constexpr
-  short sa[cxx11test::get_val()] = { 0 };
-}
-{
-  // Test initializer lists
-  cxx11test::testinit il = { 4323, 435234.23544 };
-}
-{
-  // Test range-based for
-  int array[] = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3,
-                 14, 19, 17, 8, 6, 20, 16, 2, 11, 1};
-  for (auto &x : array) { x += 23; }
-}
-{
-  // Test lambda expressions
-  using cxx11test::eval;
-  assert (eval ([](int x) { return x*2; }, 21) == 42);
-  double d = 2.0;
-  assert (eval ([&](double x) { return d += x; }, 3.0) == 5.0);
-  assert (d == 5.0);
-  assert (eval ([=](double x) mutable { return d += x; }, 4.0) == 9.0);
-  assert (d == 5.0);
-}
-{
-  // Test use of variadic templates
-  using cxx11test::sum;
-  auto a = sum(1);
-  auto b = sum(1, 2);
-  auto c = sum(1.0, 2.0, 3.0);
-}
-{
-  // Test constructor delegation
-  cxx11test::delegate d1;
-  cxx11test::delegate d2();
-  cxx11test::delegate d3(45);
-}
-{
-  // Test override and final
-  cxx11test::overridden o1(55464);
-}
-{
-  // Test nullptr
-  char *c = nullptr;
-}
-{
-  // Test template brackets
-  test_template<::test_template<int>> v(test_template<int>(12));
-}
-{
-  // 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";
-}
-'
-]])])
-
-AC_DEFUN([_AC_CXX_CXX98_TEST_PROGRAM],
-[AC_REQUIRE([_AC_CXX_CXX98_TEST_GLOBALS])dnl
-AC_REQUIRE([_AC_CXX_CXX98_TEST_MAIN])dnl
-m4_divert_text([INIT_PREPARE],
-[[# Test code for whether the C compiler supports C++98 (complete).
-ac_cxx_conftest_cxx98_program="${ac_cxx_conftest_cxx98_globals}
-int
-main (int argc, char **argv)
-{
-  int ok = 0;
-  ${ac_cxx_conftest_cxx98_main}
-  return ok;
-}
-"
-]])])
-
-AC_DEFUN([_AC_CXX_CXX11_TEST_PROGRAM],
-[AC_REQUIRE([_AC_CXX_CXX98_TEST_GLOBALS])dnl
-AC_REQUIRE([_AC_CXX_CXX98_TEST_MAIN])dnl
-AC_REQUIRE([_AC_CXX_CXX11_TEST_GLOBALS])dnl
-AC_REQUIRE([_AC_CXX_CXX11_TEST_MAIN])dnl
-m4_divert_text([INIT_PREPARE],
-[[# Test code for whether the C compiler supports C++11 (complete).
-ac_cxx_conftest_cxx11_program="${ac_cxx_conftest_cxx98_globals}
-${ac_cxx_conftest_cxx11_globals}
-
-int
-main (int argc, char **argv)
-{
-  int ok = 0;
-  ${ac_cxx_conftest_cxx98_main}
-  ${ac_cxx_conftest_cxx11_main}
-  return ok;
-}
-"
-]])])
-
-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
-# into a mode conforming to ISO C++ 1998 with extensions.  Do not try
-# "strictly conforming" modes (e.g. gcc's -std=c++98); they break some
-# systems' header files.  If more than one option is needed, put
-# shell quotes around the group.
-#
-# GCC           -std=gnu++98
-# Intel ICC     -std=c++98
-#   Note: because -std=c++98 puts GCC in strictly conforming mode,
-#   this option must be tested *after* -std=gnu++98.
-# IBM XL C      -qlanglvl=extended
-# HP aC++       -AA
-# Solaris       N/A (default)
-# Tru64         N/A (default, but -std gnu could be used)
-m4_define([_AC_CXX_CXX98_OPTIONS], [
-    -std=gnu++98
-    -std=c++98
-    -qlanglvl=extended
-    -AA
-])
-
-# _AC_CXX_CXX11_OPTIONS
-# ---------------------
-# Whitespace-separated list of options that might put the C++ compiler
-# into a mode conforming to ISO C++ 2011 with extensions.  Do not try
-# "strictly conforming" modes (e.g. gcc's -std=c++11); they break some
-# systems' header files.  If more than one option is needed, put
-# shell quotes around the group.
-#
-# GCC           -std=gnu++11, -std=gnu++0x
-# Intel ICC     -std=c++11, -std=c++0x
-#   Note: because -std=c++11 puts GCC in strictly conforming mode,
-#   these options must be tested *after* -std=gnu++11.
-# IBM XL C      -qlanglvl=extended0x (pre-V12.1)
-# HP aC++       -AA
-# Solaris       N/A (no support)
-# Tru64         N/A (no support)
-m4_define([_AC_CXX_CXX11_OPTIONS], [
-    -std=gnu++11
-    -std=gnu++0x
-    -std=c++11
-    -std=c++0x
-    -qlanglvl=extended0x
-    -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.
-#
-# Check whether the C++ compiler accepts features of EDITION of the
-# C++ standard.  EDITION should be a two-digit year (e.g. 98, 11).
-# (FIXME: Switch to four-digit years for futureproofing.)
-# This is done by compiling the test program defined by
-# _AC_C_CXX{EDITION}_TEST_PROGRAM, first with no additional
-# command-line options, and then with each of the options
-# in the space-separated list defined by _AC_C_CXX{EDITION}_OPTIONS.
-#
-# If we find a way to make the test program compile, set cache variable
-# ac_cv_prog_cxx_cxxEDITION to the options required (if any), and add those
-# options to $CXX.  Set shell variable ac_prog_cxx_stdcxx to 'cxxEDITION',
-# and set shell variable ac_cv_prog_cxx_stdcxx to the options required.
-# (Neither of these variables is AC_SUBSTed.  ac_cv_prog_cxx_stdcxx used
-# to be a cache variable and is preserved with this name for backward
-# compatibility.)  Otherwise, ac_cv_prog_cxx_cxxEDITION is set to 'no'
-# and the other variables are not changed.
-#
-# If ac_prog_cxx_stdcxx is already set to a value other than 'no',
-# the shell code produced by this macro does nothing.  This is so
-# _AC_PROG_CXX_STDCXX_EDITION can use m4_map to iterate through
-# all the editions.
-AC_DEFUN([_AC_PROG_CXX_STDCXX_EDITION_TRY],
-[AC_LANG_ASSERT([C++])]dnl
-[AC_REQUIRE([_AC_CXX_CXX$1_TEST_PROGRAM])]dnl
-[AS_IF([test x$ac_prog_cxx_stdcxx = xno],
-[AC_MSG_CHECKING([for $CXX option to enable C++$1 features])
-AC_CACHE_VAL(ac_cv_prog_cxx_cxx$1,
-[ac_cv_prog_cxx_cxx$1=no
-ac_save_CXX=$CXX
-AC_LANG_CONFTEST([AC_LANG_DEFINES_PROVIDED][$][ac_cxx_conftest_cxx$1_program])
-for ac_arg in '' m4_normalize(m4_defn([_AC_CXX_CXX$1_OPTIONS]))
-do
-  CXX="$ac_save_CXX $ac_arg"
-  _AC_COMPILE_IFELSE([], [ac_cv_prog_cxx_cxx$1=$ac_arg])
-  test "x$ac_cv_prog_cxx_cxx$1" != "xno" && break
-done
-rm -f conftest.$ac_ext
-CXX=$ac_save_CXX])
-AS_IF([test "x$ac_cv_prog_cxx_cxx$1" = xno],
-  [AC_MSG_RESULT([unsupported])],
-  [AS_IF([test "x$ac_cv_prog_cxx_cxx$1" = x],
-    [AC_MSG_RESULT([none needed])],
-    [AC_MSG_RESULT([$ac_cv_prog_cxx_cxx$1])
-     CXX="$CXX $ac_cv_prog_cxx_cxx$1"])
-  ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx$1
-  ac_prog_cxx_stdcxx=cxx$1])])
-])
-
-# _AC_PROG_CXX_STDCXX_EDITION
-# ---------------------------
-# Detect the most recent edition of the ISO C++ standard that is
-# supported by the C++ compiler.  Add command-line options to $CXX,
-# if necessary, to enable support for this edition.  Set the shell
-# 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], [23, 20, 17, 14, 11, 98])])
-- 
2.43.0


[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux