Skip to content

Commit

Permalink
Merge branch 'cxx17' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed May 1, 2024
2 parents 9a6c210 + 7be9372 commit 5df8992
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 50 deletions.
2 changes: 1 addition & 1 deletion build/bin/sage-build-env-config.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#
##########################################################################

# The configured CXX without special flags added that enable C++11 support
# The configured CXX without special flags added that enable C++17 support
export SAGE_CXX_WITHOUT_STD="@SAGE_CXX_WITHOUT_STD@"

# Export SAGE_FAT_BINARY if this was enabled during configure.
Expand Down
10 changes: 5 additions & 5 deletions build/pkgs/gcc/spkg-configure.m4
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ SAGE_SPKG_CONFIGURE_BASE([gcc], [
])
AC_LANG_POP()
# Save the value of CXX without special flags to enable C++11 support
# Save the value of CXX without special flags to enable C++17 support
AS_VAR_SET([SAGE_CXX_WITHOUT_STD], [$CXX])
AC_SUBST(SAGE_CXX_WITHOUT_STD)
# Modify CXX to include an option that enables C++11 support if necessary
AX_CXX_COMPILE_STDCXX_11([], optional)
if test $HAVE_CXX11 != 1; then
SAGE_MUST_INSTALL_GCC([your C++ compiler does not support C++11])
# Modify CXX to include an option that enables C++17 support if necessary
AX_CXX_COMPILE_STDCXX_17([], optional)
if test $HAVE_CXX17 != 1; then
SAGE_MUST_INSTALL_GCC([your C++ compiler does not support C++17])
fi
AC_SUBST(CXX)
Expand Down
92 changes: 81 additions & 11 deletions m4/ax_cxx_compile_stdcxx.m4
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
#
# Check for baseline language coverage in the compiler for the specified
# version of the C++ standard. If necessary, add switches to CXX and
# CXXCPP to enable support. VERSION may be '11' (for the C++11 standard)
# or '14' (for the C++14 standard).
# CXXCPP to enable support. VERSION may be '11', '14', '17', or '20' for
# the respective C++ standard version.
#
# The second argument, if specified, indicates whether you insist on an
# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
# -std=c++11). If neither is specified, you get whatever works, with
# preference for an extended mode.
# preference for no added switch, and then for an extended mode.
#
# The third argument, if specified 'mandatory' or if left unspecified,
# indicates that baseline support for the specified C++ standard is
Expand All @@ -34,13 +34,16 @@
# Copyright (c) 2015 Paul Norman <penorman@mac.com>
# Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu>
# Copyright (c) 2016, 2018 Krzesimir Nowak <qdlacz@gmail.com>
# Copyright (c) 2019 Enji Cooper <yaneurabeya@gmail.com>
# Copyright (c) 2020 Jason Merrill <jason@redhat.com>
# Copyright (c) 2021 Jörn Heusipp <osmanx@problemloesungsmaschine.de>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 10
#serial 18

dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
dnl (serial version number 13).
Expand All @@ -49,6 +52,7 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
m4_if([$1], [11], [ax_cxx_compile_alternatives="11 0x"],
[$1], [14], [ax_cxx_compile_alternatives="14 1y"],
[$1], [17], [ax_cxx_compile_alternatives="17 1z"],
[$1], [20], [ax_cxx_compile_alternatives="20"],
[m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl
m4_if([$2], [], [],
[$2], [ext], [],
Expand All @@ -61,6 +65,16 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
AC_LANG_PUSH([C++])dnl
ac_success=no
m4_if([$2], [], [dnl
AC_CACHE_CHECK(whether $CXX supports C++$1 features by default,
ax_cv_cxx_compile_cxx$1,
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
[ax_cv_cxx_compile_cxx$1=yes],
[ax_cv_cxx_compile_cxx$1=no])])
if test x$ax_cv_cxx_compile_cxx$1 = xyes; then
ac_success=yes
fi])
m4_if([$2], [noext], [], [dnl
if test x$ac_success = xno; then
for alternative in ${ax_cxx_compile_alternatives}; do
Expand Down Expand Up @@ -90,9 +104,18 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
dnl HP's aCC needs +std=c++11 according to:
dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf
dnl Cray's crayCC needs "-h std=c++11"
dnl MSVC needs -std:c++NN for C++17 and later (default is C++14)
for alternative in ${ax_cxx_compile_alternatives}; do
for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}" MSVC; do
if test x"$switch" = xMSVC; then
dnl AS_TR_SH maps both `:` and `=` to `_` so -std:c++17 would collide
dnl with -std=c++17. We suffix the cache variable name with _MSVC to
dnl avoid this.
switch=-std:c++${alternative}
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_${switch}_MSVC])
else
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
fi
AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
$cachevar,
[ac_save_CXX="$CXX"
Expand Down Expand Up @@ -139,20 +162,31 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11],
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
)


dnl Test body for checking C++14 support

m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14],
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
)

dnl Test body for checking C++17 support

m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17],
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
_AX_CXX_COMPILE_STDCXX_testbody_new_in_17
)

dnl Test body for checking C++20 support

m4_define([_AX_CXX_COMPILE_STDCXX_testbody_20],
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
_AX_CXX_COMPILE_STDCXX_testbody_new_in_17
_AX_CXX_COMPILE_STDCXX_testbody_new_in_20
)


dnl Tests for new features in C++11

m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
Expand All @@ -164,7 +198,11 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
#error "This is not a C++ compiler"
#elif __cplusplus < 201103L
// MSVC always sets __cplusplus to 199711L in older versions; newer versions
// only set it correctly if /Zc:__cplusplus is specified as well as a
// /std:c++NN switch:
// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
#elif __cplusplus < 201103L && !defined _MSC_VER
#error "This is not a C++11 compiler"
Expand All @@ -189,11 +227,13 @@ namespace cxx11
struct Base
{
virtual ~Base() {}
virtual void f() {}
};
struct Derived : public Base
{
virtual ~Derived() override {}
virtual void f() override {}
};
Expand Down Expand Up @@ -453,7 +493,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[
#error "This is not a C++ compiler"
#elif __cplusplus < 201402L
#elif __cplusplus < 201402L && !defined _MSC_VER
#error "This is not a C++14 compiler"
Expand Down Expand Up @@ -577,7 +617,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[
#error "This is not a C++ compiler"
#elif __cplusplus < 201703L
#elif __cplusplus < 201703L && !defined _MSC_VER
#error "This is not a C++17 compiler"
Expand Down Expand Up @@ -943,6 +983,36 @@ namespace cxx17
} // namespace cxx17
#endif // __cplusplus < 201703L
#endif // __cplusplus < 201703L && !defined _MSC_VER
]])


dnl Tests for new features in C++20

m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_20], [[
#ifndef __cplusplus
#error "This is not a C++ compiler"
#elif __cplusplus < 202002L && !defined _MSC_VER
#error "This is not a C++20 compiler"
#else
#include <version>
namespace cxx20
{
// As C++20 supports feature test macros in the standard, there is no
// immediate need to actually test for feature availability on the
// Autoconf side.
} // namespace cxx20
#endif // __cplusplus < 202002L && !defined _MSC_VER
]])
18 changes: 7 additions & 11 deletions m4/ax_cxx_compile_stdcxx_11.m4 → m4/ax_cxx_compile_stdcxx_17.m4
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
# =============================================================================
# https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
# https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_17.html
# =============================================================================
#
# SYNOPSIS
#
# AX_CXX_COMPILE_STDCXX_11([ext|noext], [mandatory|optional])
# AX_CXX_COMPILE_STDCXX_17([ext|noext], [mandatory|optional])
#
# DESCRIPTION
#
# Check for baseline language coverage in the compiler for the C++11
# Check for baseline language coverage in the compiler for the C++17
# standard; if necessary, add switches to CXX and CXXCPP to enable
# support.
#
# This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX
# macro with the version set to C++11. The two optional arguments are
# macro with the version set to C++17. The two optional arguments are
# forwarded literally as the second and third argument respectively.
# Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for
# more information. If you want to use this macro, you also need to
# download the ax_cxx_compile_stdcxx.m4 file.
#
# LICENSE
#
# Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
# Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
# Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com>
# Copyright (c) 2015 Paul Norman <penorman@mac.com>
# Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu>
# Copyright (c) 2016 Krzesimir Nowak <qdlacz@gmail.com>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 18
#serial 2

AX_REQUIRE_DEFINED([AX_CXX_COMPILE_STDCXX])
AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [AX_CXX_COMPILE_STDCXX([11], [$1], [$2])])
AC_DEFUN([AX_CXX_COMPILE_STDCXX_17], [AX_CXX_COMPILE_STDCXX([17], [$1], [$2])])
14 changes: 5 additions & 9 deletions m4/sage_check_python_for_venv.m4
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ AC_DEFUN([SAGE_PYTHON_CHECK_DISTUTILS], [
echo PYTHON_EXE conftest.py --verbose build --build-base=conftest.dir >& AS_MESSAGE_LOG_FD 2>&1
AS_IF([PYTHON_EXE conftest.py --verbose build --build-base=conftest.dir >& AS_MESSAGE_LOG_FD 2>&1 ], [
COMMANDS_IF_DISTUTILS_GOOD], [
reason="distutils cannot build a C++ 11 extension"
reason="distutils cannot build a C++ 17 extension"
COMMANDS_IF_DISTUTILS_NOT_GOOD
])
], [
Expand Down Expand Up @@ -172,16 +172,12 @@ PyInit_spam(void)
m = PyModule_Create(&spammodule);
return m;
}
// Partial C++11 test, from ax_cxx_compile_stdcxx.m4
// Partial C++17 test, from ax_cxx_compile_stdcxx.m4
namespace test_noexcept
namespace test_constexpr_lambdas
{
int f() { return 0; }
int g() noexcept { return 0; }
static_assert(noexcept(f()) == false, "");
static_assert(noexcept(g()) == true, "");
constexpr int foo = [](){return 42;}();
}
Expand All @@ -194,7 +190,7 @@ from $distutils_core import setup
from $distutils_extension import Extension
from sys import exit
modules = list((Extension("config_check_distutils_cxx", list(("conftest.cpp",)),
extra_compile_args=list(("-std=c++11",)), language="c++"),))
extra_compile_args=list(("-std=c++17",)), language="c++"),))
setup(name="config_check_distutils_cxx", ext_modules=modules)
exit(0)
EOF
Expand Down
6 changes: 4 additions & 2 deletions src/sage/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,16 +472,18 @@ def uname_specific(name, value, alternative):
# file (possibly because of confusion between CFLAGS and CXXFLAGS?).
# This is not a problem in practice since LinBox depends on
# fflas-ffpack and fflas-ffpack does add such a C++11 flag.
#
# Based on the above, we have updated mechanically from -std=gnu++11 to -std=gnu++17.
if "LINBOX_CFLAGS" in aliases:
aliases["LINBOX_CFLAGS"].append("-std=gnu++11")
aliases["LINBOX_CFLAGS"].append("-std=gnu++17")

try:
aliases["M4RI_CFLAGS"].remove("-pedantic")
except (ValueError, KeyError):
pass

# NTL
aliases["NTL_CFLAGS"] = ['-std=c++11']
aliases["NTL_CFLAGS"] = ['-std=c++17']
aliases["NTL_INCDIR"] = [NTL_INCDIR] if NTL_INCDIR else []
aliases["NTL_LIBDIR"] = [NTL_LIBDIR] if NTL_LIBDIR else []
aliases["NTL_LIBRARIES"] = ['ntl']
Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/base/boost_graph.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# distutils: language = c++
# distutils: extra_compile_args = -std=c++11
# distutils: extra_compile_args = -std=c++17

#*****************************************************************************
# Copyright (C) 2015 Michele Borassi michele.borassi@imtlucca.it
Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/bliss.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# distutils: language = c++
# distutils: extra_compile_args = -std=c++11
# distutils: extra_compile_args = -std=c++17
# distutils: libraries = bliss
# sage_setup: distribution = sagemath-bliss

Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/graph_decompositions/tdlib.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# distutils: language = c++
# distutils: extra_compile_args = -std=c++11
# distutils: extra_compile_args = -std=c++17
# sage_setup: distribution = sagemath-tdlib

r"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/libs/m4ri.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# distutils: extra_compile_args = -std=c++11
# distutils: extra_compile_args = -std=c++17
# distutils: language = c++

cdef extern from "m4ri/m4ri.h":
Expand Down
2 changes: 1 addition & 1 deletion src/sage/libs/polybori/decl.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# distutils: language = c++
# distutils: extra_compile_args = -std=c++11
# distutils: extra_compile_args = -std=c++17

from libcpp.string cimport string as std_string
from libcpp.vector cimport vector
Expand Down
2 changes: 1 addition & 1 deletion src/sage/libs/singular/decl.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# distutils: libraries = SINGULAR_LIBRARIES
# distutils: library_dirs = SINGULAR_LIBDIR
# distutils: language = c++
# distutils: extra_compile_args = -std=c++11
# distutils: extra_compile_args = -std=c++17

"""
Declarations of Singular's C/C++ Functions
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modular/arithgroup/farey_symbol.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# distutils: sources = sage/modular/arithgroup/sl2z.cpp sage/modular/arithgroup/farey.cpp
# distutils: language = c++
# distutils: extra_compile_args = -std=c++11
# distutils: extra_compile_args = -std=c++17
# sage.doctest: needs sage.libs.pari
r"""
Farey symbol for arithmetic subgroups of `\PSL_2(\ZZ)`
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/finite_rings/element_givaro.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# distutils: extra_compile_args = GIVARO_CFLAGS -std=c++11
# distutils: extra_compile_args = GIVARO_CFLAGS -std=c++17
# distutils: include_dirs = GIVARO_INCDIR

from libcpp.vector cimport vector
Expand Down
2 changes: 1 addition & 1 deletion src/sage/symbolic/expression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# distutils: sources = sage/symbolic/ginac/add.cpp sage/symbolic/ginac/archive.cpp sage/symbolic/ginac/assume.cpp sage/symbolic/ginac/basic.cpp sage/symbolic/ginac/cmatcher.cpp sage/symbolic/ginac/constant.cpp sage/symbolic/ginac/context.cpp sage/symbolic/ginac/ex.cpp sage/symbolic/ginac/expair.cpp sage/symbolic/ginac/expairseq.cpp sage/symbolic/ginac/exprseq.cpp sage/symbolic/ginac/fderivative.cpp sage/symbolic/ginac/function.cpp sage/symbolic/ginac/function_info.cpp sage/symbolic/ginac/infinity.cpp sage/symbolic/ginac/infoflagbase.cpp sage/symbolic/ginac/inifcns.cpp sage/symbolic/ginac/inifcns_comb.cpp sage/symbolic/ginac/inifcns_gamma.cpp sage/symbolic/ginac/inifcns_hyperb.cpp sage/symbolic/ginac/inifcns_hyperg.cpp sage/symbolic/ginac/inifcns_nstdsums.cpp sage/symbolic/ginac/inifcns_orthopoly.cpp sage/symbolic/ginac/inifcns_trans.cpp sage/symbolic/ginac/inifcns_trig.cpp sage/symbolic/ginac/inifcns_zeta.cpp sage/symbolic/ginac/lst.cpp sage/symbolic/ginac/matrix.cpp sage/symbolic/ginac/mpoly-giac.cpp sage/symbolic/ginac/mpoly-ginac.cpp sage/symbolic/ginac/mpoly-singular.cpp sage/symbolic/ginac/mpoly.cpp sage/symbolic/ginac/mul.cpp sage/symbolic/ginac/normal.cpp sage/symbolic/ginac/numeric.cpp sage/symbolic/ginac/operators.cpp sage/symbolic/ginac/order.cpp sage/symbolic/ginac/power.cpp sage/symbolic/ginac/print.cpp sage/symbolic/ginac/pseries.cpp sage/symbolic/ginac/py_funcs.cpp sage/symbolic/ginac/registrar.cpp sage/symbolic/ginac/relational.cpp sage/symbolic/ginac/remember.cpp sage/symbolic/ginac/sum.cpp sage/symbolic/ginac/symbol.cpp sage/symbolic/ginac/templates.cpp sage/symbolic/ginac/upoly-ginac.cpp sage/symbolic/ginac/useries.cpp sage/symbolic/ginac/utils.cpp sage/symbolic/ginac/wildcard.cpp
# distutils: language = c++
# distutils: libraries = flint gmp SINGULAR_LIBRARIES
# distutils: extra_compile_args = -std=c++11 SINGULAR_CFLAGS
# distutils: extra_compile_args = -std=c++17 SINGULAR_CFLAGS
# distutils: depends = ginac/add.h ginac/archive.h ginac/assertion.h ginac/assume.h ginac/basic.h ginac/class_info.h ginac/cmatcher.h ginac/compiler.h ginac/constant.h ginac/container.h ginac/context.h ginac/ex.h ginac/ex_utils.h ginac/expair.h ginac/expairseq.h ginac/exprseq.h ginac/extern_templates.h ginac/fderivative.h ginac/flags.h ginac/function.h ginac/ginac.h ginac/infinity.h ginac/infoflagbase.h ginac/inifcns.h ginac/lst.h ginac/matrix.h ginac/mpoly.h ginac/mul.h ginac/normal.h ginac/numeric.h ginac/operators.h ginac/order.h ginac/optional.hpp ginac/power.h ginac/print.h ginac/pseries.h ginac/ptr.h ginac/py_funcs.h ginac/pynac-config.h ginac/registrar.h ginac/relational.h ginac/remember.h ginac/sum.h ginac/symbol.h ginac/templates.h ginac/tostring.h ginac/upoly.h ginac/useries-flint.h ginac/useries.h ginac/utils.h ginac/wildcard.h
# distutils: include_dirs = SINGULAR_INCDIR
# pynac/basic.h includes
Expand Down
Loading

0 comments on commit 5df8992

Please sign in to comment.