Commit 66730ef6 authored by Kenton Varda's avatar Kenton Varda

We now require C++14.

I'm tired of working around missing features that were added in C++14. It's four years old now, compilers should support it.
parent df67f268
......@@ -7,12 +7,12 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(CheckIncludeFileCXX)
include(GNUInstallDirs)
if(MSVC)
check_include_file_cxx(initializer_list HAS_CXX11)
check_include_file_cxx(initializer_list HAS_CXX14)
else()
check_include_file_cxx(initializer_list HAS_CXX11 "-std=gnu++0x")
check_include_file_cxx(initializer_list HAS_CXX14 "-std=gnu++1y")
endif()
if(NOT HAS_CXX11)
message(SEND_ERROR "Requires a C++11 compiler and standard library.")
if(NOT HAS_CXX14)
message(SEND_ERROR "Requires a C++14 compiler and standard library.")
endif()
# these arguments are passed to all install(TARGETS) calls
......@@ -66,7 +66,7 @@ else()
add_compile_options(-Wall -Wextra -Wno-strict-aliasing -Wno-sign-compare -Wno-unused-parameter)
if(DEFINED CMAKE_CXX_EXTENSIONS AND NOT CMAKE_CXX_EXTENSIONS)
message(SEND_ERROR "Cap'n Proto requires compiler-specific extensions (e.g., -std=gnu++11). Please leave CMAKE_CXX_EXTENSIONS undefined or ON.")
message(SEND_ERROR "Cap'n Proto requires compiler-specific extensions (e.g., -std=gnu++14). Please leave CMAKE_CXX_EXTENSIONS undefined or ON.")
endif()
if (NOT ANDROID)
......
......@@ -16,19 +16,19 @@ all:
echo "You probably accidentally told Eclipse to build. Stopping."
once:
CXXFLAGS="$(EXTRA_FLAG) -std=c++11 -O2 -DNDEBUG -Wall" LIBS='-lz -pthread' $(EKAM) -j6
CXXFLAGS="$(EXTRA_FLAG) -std=c++14 -O2 -DNDEBUG -Wall" LIBS='-lz -pthread' $(EKAM) -j6
continuous:
CXXFLAGS="$(EXTRA_FLAG) -std=c++11 -g -DCAPNP_DEBUG_TYPES=1 -Wall" LIBS='-lz -pthread' $(EKAM) -j6 -c -n :51315
CXXFLAGS="$(EXTRA_FLAG) -std=c++14 -g -DCAPNP_DEBUG_TYPES=1 -Wall" LIBS='-lz -pthread' $(EKAM) -j6 -c -n :51315
continuous-opt:
CXXFLAGS="$(EXTRA_FLAG) -std=c++11 -O2 -DNDEBUG -Wall" LIBS='-lz -pthread' $(EKAM) -j6 -c -n :51315
CXXFLAGS="$(EXTRA_FLAG) -std=c++14 -O2 -DNDEBUG -Wall" LIBS='-lz -pthread' $(EKAM) -j6 -c -n :51315
continuous-opt3:
CXXFLAGS="$(EXTRA_FLAG) -std=c++11 -O3 -DNDEBUG -Wall" LIBS='-lz -pthread' $(EKAM) -j6 -c -n :51315
CXXFLAGS="$(EXTRA_FLAG) -std=c++14 -O3 -DNDEBUG -Wall" LIBS='-lz -pthread' $(EKAM) -j6 -c -n :51315
continuous-opts:
CXXFLAGS="$(EXTRA_FLAG) -std=c++11 -Os -DNDEBUG -Wall" LIBS='-lz -pthread' $(EKAM) -j6 -c -n :51315
CXXFLAGS="$(EXTRA_FLAG) -std=c++14 -Os -DNDEBUG -Wall" LIBS='-lz -pthread' $(EKAM) -j6 -c -n :51315
clean:
rm -rf bin lib tmp
......@@ -136,7 +136,7 @@ function(_capnp_import_pkg_config_target target)
set_target_properties(CapnProto::${target} PROPERTIES
${imported_soname_property}
IMPORTED_LOCATION "${target_location}"
INTERFACE_COMPILE_FEATURES "cxx_constexpr"
INTERFACE_COMPILE_FEATURES "cxx_std_14"
INTERFACE_COMPILE_OPTIONS "${${target}_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${${target}_INCLUDE_DIRS}"
......
......@@ -50,7 +50,7 @@ AC_ARG_ENABLE([reflection], [
AC_PROG_CC
AC_PROG_CXX
AC_LANG([C++])
AX_CXX_COMPILE_STDCXX_11
AX_CXX_COMPILE_STDCXX_14
AS_CASE("${host_os}", *mingw*, [
# We don't use pthreads on MinGW.
......
# ============================================================================
# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
# Additionally modified to detect -stdlib by Kenton Varda.
# Further modified for C++14 by Kenton Varda.
# ============================================================================
#
# SYNOPSIS
#
# AX_CXX_COMPILE_STDCXX_11([ext|noext])
# AX_CXX_COMPILE_STDCXX_14([ext|noext])
#
# DESCRIPTION
#
# Check for baseline language coverage in the compiler for the C++11
# Check for baseline language coverage in the compiler for the C++14
# standard; if necessary, add switches to CXXFLAGS to enable support.
# Errors out if no mode that supports C++11 baseline syntax can be found.
# Errors out if no mode that supports C++14 baseline syntax can be found.
# The 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).
# 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.
#
......@@ -42,7 +43,7 @@
#serial 1
m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [
m4_define([_AX_CXX_COMPILE_STDCXX_14_testbody], [[
template <typename T>
struct check
{
......@@ -78,7 +79,18 @@ m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [
#include <type_traits>
#endif
#endif
])
// C++14 stuff
auto deduceReturnType(int i) { return i; }
auto genericLambda = [](auto x, auto y) { return x + y; };
auto captureExpressions = [x = 123]() { return x; };
// Avoid unused variable warnings.
int foo() {
return genericLambda(1, 2) + captureExpressions();
}
]])
m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody_lib], [
#include <initializer_list>
......@@ -87,31 +99,31 @@ m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody_lib], [
#include <thread>
])
AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
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_11])])dnl
[m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_14])])dnl
AC_LANG_ASSERT([C++])dnl
ac_success=no
AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
ax_cv_cxx_compile_cxx11,
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
[ax_cv_cxx_compile_cxx11=yes],
[ax_cv_cxx_compile_cxx11=no])])
if test x$ax_cv_cxx_compile_cxx11 = xyes; then
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++11 -std=gnu++0x; do
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
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_CXX="$CXX"
CXX="$CXX $switch"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_14_testbody])],
[eval $cachevar=yes],
[eval $cachevar=no])
CXX="$ac_save_CXX"])
......@@ -125,13 +137,13 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
m4_if([$1], [ext], [], [dnl
if test x$ac_success = xno; then
for switch in -std=c++11 -std=c++0x; do
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
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_CXX="$CXX"
CXX="$CXX $switch"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_14_testbody])],
[eval $cachevar=yes],
[eval $cachevar=no])
CXX="$ac_save_CXX"])
......@@ -144,7 +156,7 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
fi])
if test x$ac_success = xno; then
AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
AC_MSG_ERROR([*** A compiler with support for C++14 language features is required.])
else
ac_success=no
AC_CACHE_CHECK(whether $CXX supports C++11 library features by default,
......
......@@ -23,12 +23,12 @@
//
// If Cap'n Proto is installed, build the sample like:
// capnp compile -oc++ addressbook.capnp
// c++ -std=c++11 -Wall addressbook.c++ addressbook.capnp.c++ `pkg-config --cflags --libs capnp` -o addressbook
// c++ -std=c++14 -Wall addressbook.c++ addressbook.capnp.c++ `pkg-config --cflags --libs capnp` -o addressbook
//
// If Cap'n Proto is not installed, but the source is located at $SRC and has been
// compiled in $BUILD (often both are simply ".." from here), you can do:
// $BUILD/capnp compile -I$SRC/src -o$BUILD/capnpc-c++ addressbook.capnp
// c++ -std=c++11 -Wall addressbook.c++ addressbook.capnp.c++ -I$SRC/src -L$BUILD/.libs -lcapnp -lkj -o addressbook
// c++ -std=c++14 -Wall addressbook.c++ addressbook.capnp.c++ -I$SRC/src -L$BUILD/.libs -lcapnp -lkj -o addressbook
//
// Run like:
// ./addressbook write | ./addressbook read
......
......@@ -6,16 +6,16 @@
set -exuo pipefail
capnpc -oc++ addressbook.capnp
c++ -std=c++11 -Wall addressbook.c++ addressbook.capnp.c++ \
c++ -std=c++14 -Wall addressbook.c++ addressbook.capnp.c++ \
$(pkg-config --cflags --libs capnp) -o addressbook
./addressbook write | ./addressbook read
./addressbook dwrite | ./addressbook dread
rm addressbook addressbook.capnp.c++ addressbook.capnp.h
capnpc -oc++ calculator.capnp
c++ -std=c++11 -Wall calculator-client.c++ calculator.capnp.c++ \
c++ -std=c++14 -Wall calculator-client.c++ calculator.capnp.c++ \
$(pkg-config --cflags --libs capnp-rpc) -o calculator-client
c++ -std=c++11 -Wall calculator-server.c++ calculator.capnp.c++ \
c++ -std=c++14 -Wall calculator-server.c++ calculator.capnp.c++ \
$(pkg-config --cflags --libs capnp-rpc) -o calculator-server
rm -f /tmp/capnp-calculator-example-$$
./calculator-server unix:/tmp/capnp-calculator-example-$$ &
......
......@@ -66,8 +66,7 @@ set(kj-std_headers
)
add_library(kj ${kj_sources})
add_library(CapnProto::kj ALIAS kj)
target_compile_features(kj PUBLIC cxx_constexpr)
# Requiring the cxx_std_11 metafeature would be preferable, but that doesn't exist until CMake 3.8.
target_compile_features(kj PUBLIC cxx_std_14)
if(UNIX AND NOT ANDROID)
target_link_libraries(kj PUBLIC pthread)
......
......@@ -30,33 +30,26 @@
#endif
#ifndef KJ_NO_COMPILER_CHECK
#if __cplusplus < 201103L && !__CDT_PARSER__ && !_MSC_VER
#error "This code requires C++11. Either your compiler does not support it or it is not enabled."
#if __cplusplus < 201402L && !__CDT_PARSER__ && !_MSC_VER
#error "This code requires C++14. Either your compiler does not support it or it is not enabled."
#ifdef __GNUC__
// Compiler claims compatibility with GCC, so presumably supports -std.
#error "Pass -std=c++11 on the compiler command line to enable C++11."
#error "Pass -std=c++14 on the compiler command line to enable C++14."
#endif
#endif
#ifdef __GNUC__
#if __clang__
#if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 2)
#warning "This library requires at least Clang 3.2."
#elif defined(__apple_build_version__) && __apple_build_version__ <= 4250028
#warning "This library requires at least Clang 3.2. XCode 4.6's Clang, which claims to be "\
"version 4.2 (wat?), is actually built from some random SVN revision between 3.1 "\
"and 3.2. Unfortunately, it is insufficient for compiling this library. You can "\
"download the real Clang 3.2 (or newer) from the Clang web site. Step-by-step "\
"instructions can be found in Cap'n Proto's documentation: "\
"http://kentonv.github.io/capnproto/install.html#clang_32_on_mac_osx"
#elif __cplusplus >= 201103L && !__has_include(<initializer_list>)
#warning "Your compiler supports C++11 but your C++ standard library does not. If your "\
#if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 4)
#warning "This library requires at least Clang 3.4."
#elif __cplusplus >= 201402L && !__has_include(<initializer_list>)
#warning "Your compiler supports C++14 but your C++ standard library does not. If your "\
"system has libc++ installed (as should be the case on e.g. Mac OSX), try adding "\
"-stdlib=libc++ to your CXXFLAGS."
#endif
#else
#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)
#warning "This library requires at least GCC 4.7."
#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 9)
#warning "This library requires at least GCC 4.9."
#endif
#endif
#elif defined(_MSC_VER)
......@@ -64,8 +57,8 @@
#error "You need Visual Studio 2017 or better to compile this code."
#endif
#else
#warning "I don't recognize your compiler. As of this writing, Clang and GCC are the only "\
"known compilers with enough C++11 support for this library. "\
#warning "I don't recognize your compiler. As of this writing, Clang, GCC, and Visual Studio "\
"are the only known compilers with enough C++14 support for this library. "\
"#define KJ_NO_COMPILER_CHECK to make this warning go away."
#endif
#endif
......
......@@ -362,7 +362,7 @@ doit make -j$PARALLEL check
if [ $IS_CLANG = no ]; then
# Verify that generated code compiles with pedantic warnings. Make sure to treat capnp headers
# as system headers so warnings in them are ignored.
doit ${CXX:-g++} -isystem src -std=c++11 -fno-permissive -pedantic -Wall -Wextra -Werror \
doit ${CXX:-g++} -isystem src -std=c++1y -fno-permissive -pedantic -Wall -Wextra -Werror \
-c src/capnp/test.capnp.c++ -o /dev/null
fi
......@@ -378,13 +378,13 @@ test "x$(which capnpc-c++)" = "x$STAGING/bin/capnpc-c++"
cd samples
doit capnp compile -oc++ addressbook.capnp -I"$STAGING"/include --no-standard-import
doit ${CXX:-g++} -std=c++11 addressbook.c++ addressbook.capnp.c++ -o addressbook \
doit ${CXX:-g++} -std=c++1y addressbook.c++ addressbook.capnp.c++ -o addressbook \
$CXXFLAGS $(pkg-config --cflags --libs capnp)
doit capnp compile -oc++ calculator.capnp -I"$STAGING"/include --no-standard-import
doit ${CXX:-g++} -std=c++11 calculator-client.c++ calculator.capnp.c++ -o calculator-client \
doit ${CXX:-g++} -std=c++1y calculator-client.c++ calculator.capnp.c++ -o calculator-client \
$CXXFLAGS $(pkg-config --cflags --libs capnp-rpc)
doit ${CXX:-g++} -std=c++11 calculator-server.c++ calculator.capnp.c++ -o calculator-server \
doit ${CXX:-g++} -std=c++1y calculator-server.c++ calculator.capnp.c++ -o calculator-server \
$CXXFLAGS $(pkg-config --cflags --libs capnp-rpc)
test_samples
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment