Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use and require C++17 instead of C++11 (in distro + sagelib) #37906

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions build/pkgs/brial/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tarball=brial-VERSION.tar.bz2
sha1=ea69faff56fb7068536723f3fb5b3583b8467831
sha256=deb95fc1a99b6f9324f1278fcb676a605b77d59f24683d6af87f573cb46d0a4f
sha1=653627fb80872cc392e6cbb4cafc9fdd22967b37
sha256=ca009e3722dd3f0a60d15501caed1413146c80abced57423e32ae0116f407494
upstream_url=https://github.com/BRiAl/BRiAl/releases/download/VERSION/brial-VERSION.tar.bz2
2 changes: 1 addition & 1 deletion build/pkgs/brial/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.8
1.2.12
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 @@ -474,16 +474,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
Loading
Loading