switch to C++17

Time to move on, two years after 2017.
This commit is contained in:
Max Kellermann 2019-08-02 07:25:13 +02:00
parent c764b70b3a
commit 8f981845dc
9 changed files with 103 additions and 37 deletions

2
NEWS
View File

@ -12,6 +12,8 @@ ver 0.22 (not yet released)
- ffmpeg: new plugin based on FFmpeg's libavfilter library - ffmpeg: new plugin based on FFmpeg's libavfilter library
- hdcd: new plugin based on FFmpeg's "af_hdcd" for HDCD playback - hdcd: new plugin based on FFmpeg's "af_hdcd" for HDCD playback
- volume: convert S16 to S24 to preserve quality and reduce dithering noise - volume: convert S16 to S24 to preserve quality and reduce dithering noise
* switch to C++17
- GCC 7 or clang 4 (or newer) recommended
ver 0.21.12 (2019/08/03) ver 0.21.12 (2019/08/03)
* decoder * decoder

View File

@ -12,7 +12,7 @@ Code Style
* indent with tabs (width 8) * indent with tabs (width 8)
* don't write CPP when you can write C++: use inline functions and constexpr instead of macros * don't write CPP when you can write C++: use inline functions and constexpr instead of macros
* comment your code, document your APIs * comment your code, document your APIs
* the code should be C++14 compliant, and must compile with :program:`GCC` 6.0 and :program:`clang` 3.4 * the code should be C++17 compliant, and must compile with :program:`GCC` 7 and :program:`clang` 4
* report error conditions with C++ exceptions, preferable derived from :envvar:`std::runtime_error` * report error conditions with C++ exceptions, preferable derived from :envvar:`std::runtime_error`
* all code must be exception-safe * all code must be exception-safe
* classes and functions names use CamelCase; variables are lower-case with words separated by underscore * classes and functions names use CamelCase; variables are lower-case with words separated by underscore

View File

@ -5,7 +5,7 @@ project(
meson_version: '>= 0.49.0', meson_version: '>= 0.49.0',
default_options: [ default_options: [
'c_std=c99', 'c_std=c99',
'cpp_std=c++14' 'cpp_std=c++17'
], ],
license: 'GPLv2+', license: 'GPLv2+',
) )
@ -15,10 +15,10 @@ version_cxx = vcs_tag(input: 'src/GitVersion.cxx', output: 'GitVersion.cxx')
compiler = meson.get_compiler('cpp') compiler = meson.get_compiler('cpp')
c_compiler = meson.get_compiler('c') c_compiler = meson.get_compiler('c')
if compiler.get_id() == 'gcc' and compiler.version().version_compare('<6') if compiler.get_id() == 'gcc' and compiler.version().version_compare('<7')
warning('Your GCC version is too old. You need at least version 6.') warning('Your GCC version is too old. You need at least version 7.')
elif compiler.get_id() == 'clang' and compiler.version().version_compare('<3') elif compiler.get_id() == 'clang' and compiler.version().version_compare('<4')
warning('Your clang version is too old. You need at least version 3.') warning('Your clang version is too old. You need at least version 4.')
endif endif
conf = configuration_data() conf = configuration_data()

View File

@ -34,7 +34,7 @@
class MaskMonitor final { class MaskMonitor final {
DeferEvent defer; DeferEvent defer;
typedef BoundMethod<void(unsigned)> Callback; typedef BoundMethod<void(unsigned) noexcept> Callback;
const Callback callback; const Callback callback;
std::atomic_uint pending_mask; std::atomic_uint pending_mask;

View File

@ -44,7 +44,7 @@ class TimerEvent final {
EventLoop &loop; EventLoop &loop;
typedef BoundMethod<void()> Callback; typedef BoundMethod<void() noexcept> Callback;
const Callback callback; const Callback callback;
/** /**

View File

@ -49,7 +49,7 @@ namespace ODBus {
class AsyncRequest { class AsyncRequest {
PendingCall pending_call; PendingCall pending_call;
std::function<void(Message) noexcept> callback; std::function<void(Message)> callback;
public: public:
operator bool() const noexcept { operator bool() const noexcept {

View File

@ -32,7 +32,7 @@
#include <assert.h> #include <assert.h>
class Thread { class Thread {
typedef BoundMethod<void()> Function; typedef BoundMethod<void() noexcept> Function;
const Function f; const Function f;
#ifdef _WIN32 #ifdef _WIN32

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016 Max Kellermann <max.kellermann@gmail.com> * Copyright 2016-2018 Max Kellermann <max.kellermann@gmail.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -30,6 +30,8 @@
#ifndef BIND_METHOD_HXX #ifndef BIND_METHOD_HXX
#define BIND_METHOD_HXX #define BIND_METHOD_HXX
#include "Compiler.h"
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
@ -43,9 +45,21 @@
template<typename S=void()> template<typename S=void()>
class BoundMethod; class BoundMethod;
template<typename R, typename... Args> #if GCC_OLDER_THAN(7,0)
class BoundMethod<R(Args...)> { static constexpr bool NoExcept = false;
typedef R (*function_pointer)(void *instance, Args... args); #endif
template<typename R,
#if !GCC_OLDER_THAN(7,0)
bool NoExcept,
#endif
typename... Args>
class BoundMethod<R(Args...) noexcept(NoExcept)> {
typedef R (*function_pointer)(void *instance, Args... args)
#if !GCC_OLDER_THAN(7,0)
noexcept(NoExcept)
#endif
;
void *instance_; void *instance_;
function_pointer function; function_pointer function;
@ -91,9 +105,21 @@ namespace BindMethodDetail {
template<typename T, typename S> template<typename T, typename S>
struct MethodWithSignature; struct MethodWithSignature;
template<typename T, typename R, typename... Args> template<typename T,
struct MethodWithSignature<T, R(Args...)> { #if !GCC_OLDER_THAN(7,0)
typedef R (T::*method_pointer)(Args...); bool NoExcept,
#endif
typename R, typename... Args>
struct MethodWithSignature<T, R(Args...)
#if !GCC_OLDER_THAN(7,0)
noexcept(NoExcept)
#endif
> {
typedef R (T::*method_pointer)(Args...)
#if !GCC_OLDER_THAN(7,0)
noexcept(NoExcept)
#endif
;
}; };
/** /**
@ -104,8 +130,12 @@ struct MethodWithSignature<T, R(Args...)> {
template<typename M> template<typename M>
struct MethodSignatureHelper; struct MethodSignatureHelper;
template<typename R, typename T, typename... Args> template<typename R,
struct MethodSignatureHelper<R (T::*)(Args...)> { #if !GCC_OLDER_THAN(7,0)
bool NoExcept,
#endif
typename T, typename... Args>
struct MethodSignatureHelper<R (T::*)(Args...) noexcept(NoExcept)> {
/** /**
* The class which contains the given method (signature). * The class which contains the given method (signature).
*/ */
@ -115,7 +145,11 @@ struct MethodSignatureHelper<R (T::*)(Args...)> {
* A function type which describes the "plain" function * A function type which describes the "plain" function
* signature. * signature.
*/ */
typedef R plain_signature(Args...); typedef R plain_signature(Args...)
#if !GCC_OLDER_THAN(7,0)
noexcept(NoExcept)
#endif
;
}; };
/** /**
@ -125,9 +159,17 @@ struct MethodSignatureHelper<R (T::*)(Args...)> {
template<typename S> template<typename S>
struct MethodWrapperWithSignature; struct MethodWrapperWithSignature;
template<typename R, typename... Args> template<typename R,
struct MethodWrapperWithSignature<R(Args...)> { #if !GCC_OLDER_THAN(7,0)
typedef R (*function_pointer)(void *instance, Args...); bool NoExcept,
#endif
typename... Args>
struct MethodWrapperWithSignature<R(Args...) noexcept(NoExcept)> {
typedef R (*function_pointer)(void *instance, Args...)
#if !GCC_OLDER_THAN(7,0)
noexcept(NoExcept)
#endif
;
}; };
/** /**
@ -140,9 +182,9 @@ struct MethodWrapperWithSignature<R(Args...)> {
* @param R the return type * @param R the return type
* @param Args the method arguments * @param Args the method arguments
*/ */
template<typename T, typename M, M method, typename R, typename... Args> template<typename T, bool NoExcept, typename M, M method, typename R, typename... Args>
struct BindMethodWrapperGenerator2 { struct BindMethodWrapperGenerator2 {
static R Invoke(void *_instance, Args... args) { static R Invoke(void *_instance, Args... args) noexcept(NoExcept) {
auto &t = *(T *)_instance; auto &t = *(T *)_instance;
return (t.*method)(std::forward<Args>(args)...); return (t.*method)(std::forward<Args>(args)...);
} }
@ -159,9 +201,13 @@ struct BindMethodWrapperGenerator2 {
template<typename T, typename M, M method, typename S> template<typename T, typename M, M method, typename S>
struct BindMethodWrapperGenerator; struct BindMethodWrapperGenerator;
template<typename T, typename M, M method, typename R, typename... Args> template<typename T,
struct BindMethodWrapperGenerator<T, M, method, R(Args...)> #if !GCC_OLDER_THAN(7,0)
: BindMethodWrapperGenerator2<T, M, method, R, Args...> { bool NoExcept,
#endif
typename M, M method, typename R, typename... Args>
struct BindMethodWrapperGenerator<T, M, method, R(Args...) noexcept(NoExcept)>
: BindMethodWrapperGenerator2<T, NoExcept, M, method, R, Args...> {
}; };
template<typename T, typename S, template<typename T, typename S,
@ -180,19 +226,31 @@ MakeBindMethodWrapper() noexcept
template<typename S> template<typename S>
struct FunctionTraits; struct FunctionTraits;
template<typename R, typename... Args> template<typename R,
struct FunctionTraits<R(Args...)> { #if !GCC_OLDER_THAN(7,0)
bool NoExcept,
#endif
typename... Args>
struct FunctionTraits<R(Args...) noexcept(NoExcept)> {
/** /**
* A function type which describes the "plain" function * A function type which describes the "plain" function
* signature. * signature.
*/ */
typedef R function_type(Args...); typedef R function_type(Args...)
#if !GCC_OLDER_THAN(7,0)
noexcept(NoExcept)
#endif
;
/** /**
* A function pointer type which describes the "plain" * A function pointer type which describes the "plain"
* function signature. * function signature.
*/ */
typedef R (*pointer_type)(Args...); typedef R (*pointer_type)(Args...)
#if !GCC_OLDER_THAN(7,0)
noexcept(NoExcept)
#endif
;
}; };
/** /**
@ -205,9 +263,9 @@ struct FunctionTraits<R(Args...)> {
* @param R the return type * @param R the return type
* @param Args the function arguments * @param Args the function arguments
*/ */
template<typename F, F function, typename R, typename... Args> template<bool NoExcept, typename F, F function, typename R, typename... Args>
struct BindFunctionWrapperGenerator2 { struct BindFunctionWrapperGenerator2 {
static R Invoke(void *, Args... args) { static R Invoke(void *, Args... args) noexcept(NoExcept) {
return function(std::forward<Args>(args)...); return function(std::forward<Args>(args)...);
} }
}; };
@ -222,9 +280,13 @@ struct BindFunctionWrapperGenerator2 {
template<typename S, typename P, P function> template<typename S, typename P, P function>
struct BindFunctionWrapperGenerator; struct BindFunctionWrapperGenerator;
template<typename P, P function, typename R, typename... Args> template<typename P, P function,
struct BindFunctionWrapperGenerator<R(Args...), P, function> #if !GCC_OLDER_THAN(7,0)
: BindFunctionWrapperGenerator2<P, function, R, Args...> { bool NoExcept,
#endif
typename R, typename... Args>
struct BindFunctionWrapperGenerator<R(Args...) noexcept(NoExcept), P, function>
: BindFunctionWrapperGenerator2<NoExcept, P, function, R, Args...> {
}; };
template<typename T, typename T::pointer_type function> template<typename T, typename T::pointer_type function>

View File

@ -49,6 +49,8 @@ test('TestUtil', executable(
test('TestRewindInputStream', executable( test('TestRewindInputStream', executable(
'TestRewindInputStream', 'TestRewindInputStream',
'TestRewindInputStream.cxx', 'TestRewindInputStream.cxx',
'../src/Log.cxx',
'../src/LogBackend.cxx',
include_directories: inc, include_directories: inc,
dependencies: [ dependencies: [
input_glue_dep, input_glue_dep,