switch C++ support to C++17

As contribs keep being updated with newer versions of the language, we need to
support a more modern version of C++ going forward.

Setting -std=c++17 should not break existing contribs that are built with C++11 or C++14.
In fact we already support the mix of versions between 11 and 14 without problem.
Modern C++ compilers are designed to take care of this [1].
When switching to a new C++ version there might however be some slight differences on how the
code is interpreted. These differences [2] might trigger some build errors for removed parts.

[1] https://stackoverflow.com/questions/46746878/is-it-safe-to-link-c17-c14-and-c11-objects
[2] https://www.open-std.org/JTC1/SC22/WG21/docs/papers/2018/p0636r3.html
This commit is contained in:
Steve Lhomme 2024-01-09 08:48:09 +01:00 committed by Thomas Guillem
parent fc787fe385
commit 5dcc5ff839
6 changed files with 1057 additions and 195 deletions

View File

@ -73,7 +73,7 @@ AC_C_CONST
AC_C_INLINE
AC_C_RESTRICT
AC_LANG_PUSH([C++])
AX_CXX_COMPILE_STDCXX_14([noext], [mandatory])
AX_CXX_COMPILE_STDCXX_17([noext], [mandatory])
AX_CXX_TYPEOF
AC_LANG_POP([C++])

View File

@ -14,7 +14,7 @@ EXTRA_DIST = \
nls.m4 \
po.m4 \
progtest.m4 \
stdcxx_14.m4 \
ax_cxx_compile_stdcxx.m4 \
ax_cxx_compile_stdcxx_17.m4 \
vlc.m4 \
$(NULL)

1018
m4/ax_cxx_compile_stdcxx.m4 Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,35 @@
# =============================================================================
# https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_17.html
# =============================================================================
#
# SYNOPSIS
#
# AX_CXX_COMPILE_STDCXX_17([ext|noext], [mandatory|optional])
#
# DESCRIPTION
#
# 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++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) 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 2
AX_REQUIRE_DEFINED([AX_CXX_COMPILE_STDCXX])
AC_DEFUN([AX_CXX_COMPILE_STDCXX_17], [AX_CXX_COMPILE_STDCXX([17], [$1], [$2])])

View File

@ -1,191 +0,0 @@
# ============================================================================
# Based on http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
# ============================================================================
#
# SYNOPSIS
#
# AX_CXX_COMPILE_STDCXX_14([ext|noext],[mandatory|optional])
#
# DESCRIPTION
#
# Check for baseline language coverage in the compiler for the C++14
# standard; if necessary, add switches to CXXFLAGS to enable support.
#
# The first argument, if specified, indicates whether you insist on an
# extended mode (e.g. -std=gnu++14) or a strict conformance mode (e.g.
# -std=c++14). If neither is specified, you get whatever works, with
# preference for an extended mode.
#
# The second argument, if specified 'mandatory' or if left unspecified,
# indicates that baseline C++14 support is required and that the macro
# should error out if no mode with that support is found. If specified
# 'optional', then configuration proceeds regardless, after defining
# HAVE_CXX14 if and only if a supporting mode is found.
#
# 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 Alexey Sokolov <sokolov@google.com>
# Copyright (c) 2014, 2015 Google Inc.
# Copyright (c) 2015, 2019 VLC authors and VideoLAN
#
# 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 7
m4_define([_AX_CXX_COMPILE_STDCXX_14_testbody], [[
template <typename T>
struct check
{
static_assert(sizeof(int) <= sizeof(T), "not big enough");
};
struct Base {
virtual void f() {}
};
struct Child : public Base {
virtual void f() override {}
};
typedef check<check<bool>> right_angle_brackets;
int a;
decltype(a) b;
typedef check<int> check_type;
check_type c;
check_type&& cr = static_cast<check_type&&>(c);
auto d = a;
auto l = [](){};
// http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae
// Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function because of this
namespace test_template_alias_sfinae {
struct foo {};
template<typename T>
using member = typename T::member_type;
template<typename T>
void func(...) {}
template<typename T>
void func(member<T>*) {}
void test() {
func<foo>(0);
}
}
#include <cinttypes>
#include <climits>
#include <cstddef>
constexpr uint64_t constant_u64 = UINT64_C(0x100000000);
constexpr unsigned constant_lim = UINT_MAX;
const char *constant_fmt = "%" PRIu64, *constant_scn = "%" SCNu64;
constexpr size_t constant_align = alignof (std::max_align_t);
#include <memory>
namespace lambda_init_capture
{
void foo()
{
std::unique_ptr<int> ptr(new int);
auto lambda = [p = std::move(ptr)](){};
lambda();
}
}
#include <type_traits>
namespace traits_helper_types
{
static_assert( std::is_same<char, std::remove_pointer_t<char*>>::value, "plonk" );
}
]])
AC_DEFUN([AX_CXX_COMPILE_STDCXX_14], [dnl
m4_if([$1], [], [],
[$1], [ext], [],
[$1], [noext], [],
[m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_14])])dnl
m4_if([$2], [], [ax_cxx_compile_cxx14_required=true],
[$2], [mandatory], [ax_cxx_compile_cxx14_required=true],
[$2], [optional], [ax_cxx_compile_cxx14_required=false],
[m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_14])])
AC_LANG_PUSH([C++])dnl
ac_success=no
AC_CACHE_CHECK(whether $CXX supports C++14 features by default,
ax_cv_cxx_compile_cxx14,
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_14_testbody])],
[ax_cv_cxx_compile_cxx14=yes],
[ax_cv_cxx_compile_cxx14=no])])
if test x$ax_cv_cxx_compile_cxx14 = xyes; then
ac_success=yes
fi
m4_if([$1], [noext], [], [dnl
if test x$ac_success = xno; then
for switch in -std=gnu++14 -std=gnu++1y; do
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx14_$switch])
AC_CACHE_CHECK(whether $CXX supports C++14 features with $switch,
$cachevar,
[ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $switch"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_14_testbody])],
[eval $cachevar=yes],
[eval $cachevar=no])
CXXFLAGS="$ac_save_CXXFLAGS"])
if eval test x\$$cachevar = xyes; then
CXXFLAGS="$CXXFLAGS $switch"
ac_success=yes
break
fi
done
fi])
m4_if([$1], [ext], [], [dnl
if test x$ac_success = xno; then
for switch in -std=c++14 -std=c++1y; do
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx14_$switch])
AC_CACHE_CHECK(whether $CXX supports C++14 features with $switch,
$cachevar,
[ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $switch"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_14_testbody])],
[eval $cachevar=yes],
[eval $cachevar=no])
CXXFLAGS="$ac_save_CXXFLAGS"])
if eval test x\$$cachevar = xyes; then
CXXFLAGS="$CXXFLAGS $switch"
ac_success=yes
break
fi
done
fi])
AC_LANG_POP([C++])
if test x$ax_cxx_compile_cxx14_required = xtrue; then
if test x$ac_success = xno; then
AC_MSG_ERROR([*** A compiler with support for C++14 language features is required.])
fi
else
if test x$ac_success = xno; then
HAVE_CXX14=0
AC_MSG_NOTICE([No compiler with C++14 support was found])
else
HAVE_CXX14=1
AC_DEFINE(HAVE_CXX14,1,
[define if the compiler supports basic C++14 syntax])
fi
AC_SUBST(HAVE_CXX14)
fi
])

View File

@ -1,6 +1,6 @@
project('VLC', ['c', 'cpp'],
version: '4.0.0-dev',
default_options: ['c_std=gnu11', 'cpp_std=c++14'],
default_options: ['c_std=gnu11', 'cpp_std=c++17'],
meson_version: '>=0.60.0')
vlc_copyright_years = '1996-2018'