diff --git a/.clang-tidy b/.clang-tidy index 10ac924..d28fb6c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,202 +1,202 @@ --- Checks: # enabled - 'bugprone-*, - cert-*, - clang-analyzer-*, - concurrency-*, - cppcoreguidelines-*, - hicpp-*, - misc-*, - modernize-*, - performance-*, - portability-*, - readability-*,' + cert-*, + clang-analyzer-*, + concurrency-*, + cppcoreguidelines-*, + hicpp-*, + misc-*, + modernize-*, + performance-*, + portability-*, + readability-*,' # disabled useless checks - '-*-logical-op-parentheses, - -*-dangling-else, - -*-use-trailing-return-type, - -*-braces-around-statements, - -*-misleading-indentation, - -*-macro-usage, - -*-non-private-member-variables-in-classes, - -*-macro-parentheses, - -*-forwarding-reference-overload, - -*-pro-type-union-access, - -*-identifier-length, - -*-explicit-conversions, - -*-unconventional-assign-operator, - -*-uppercase-literal-suffix, - -*-qualified-auto, - -*-pro-bounds-constant-array-index, - -*-exception-escape, - -*-const-or-ref-data-members, - -cert-dcl21-cpp, - -*-missing-std-forward, - -*-rvalue-reference-param-not-moved, - -*-include-cleaner, - -*-swappable-parameters, - -*-reserved-identifier' + -*-dangling-else, + -*-use-trailing-return-type, + -*-braces-around-statements, + -*-misleading-indentation, + -*-macro-usage, + -*-non-private-member-variables-in-classes, + -*-macro-parentheses, + -*-forwarding-reference-overload, + -*-pro-type-union-access, + -*-identifier-length, + -*-explicit-conversions, + -*-unconventional-assign-operator, + -*-uppercase-literal-suffix, + -*-qualified-auto, + -*-pro-bounds-constant-array-index, + -*-exception-escape, + -*-const-or-ref-data-members, + -cert-dcl21-cpp, + -*-missing-std-forward, + -*-rvalue-reference-param-not-moved, + -*-include-cleaner, + -*-swappable-parameters, + -*-reserved-identifier' # disabled alias - '-bugprone-narrowing-conversions, - -cert-con36-c, - -cert-con54-cpp, - -cert-dcl03-c, - -cert-dcl16-c, - -cert-dcl37-c, - -cert-dcl51-cpp, - -cert-dcl54-cpp, - -cert-dcl59-cpp, - -cert-err09-cpp, - -cert-err61-cpp, - -cert-exp42-c, - -cert-fio38-c, - -cert-flp37-c, - -cert-msc24-c, - -cert-msc30-c, - -cert-msc32-c, - -cert-msc33-c, - -cert-msc54-cpp, - -cert-oop11-cpp, - -cert-oop54-cpp, - -cert-pos44-c, - -cert-pos47-c, - -cert-sig30-c, - -cert-str34-c, - -clang-analyzer-core.BitwiseShift, - -clang-analyzer-core.CallAndMessage, - -clang-analyzer-core.DivideZero, - -clang-analyzer-core.NonNullParamChecker, - -clang-analyzer-core.NullDereference, - -clang-analyzer-core.StackAddressEscape, - -clang-analyzer-core.UndefinedBinaryOperatorResult, - -clang-analyzer-core.VLASize, - -clang-analyzer-core.uninitialized.ArraySubscript, - -clang-analyzer-core.uninitialized.Assign, - -clang-analyzer-core.uninitialized.Branch, - -clang-analyzer-core.uninitialized.CapturedBlockVariable, - -clang-analyzer-core.uninitialized.NewArraySize, - -clang-analyzer-core.uninitialized.UndefReturn, - -clang-analyzer-cplusplus.InnerPointer, - -clang-analyzer-cplusplus.Move, - -clang-analyzer-cplusplus.NewDelete, - -clang-analyzer-cplusplus.NewDeleteLeaks, - -clang-analyzer-cplusplus.PlacementNew, - -clang-analyzer-cplusplus.PureVirtualCall, - -clang-analyzer-cplusplus.StringChecker, - -clang-analyzer-deadcode.DeadStores, - -clang-analyzer-fuchsia.HandleChecker, - -clang-analyzer-nullability.NullPassedToNonnull, - -clang-analyzer-nullability.NullReturnedFromNonnull, - -clang-analyzer-nullability.NullableDereferenced, - -clang-analyzer-nullability.NullablePassedToNonnull, - -clang-analyzer-nullability.NullableReturnedFromNonnull, - -clang-analyzer-optin.cplusplus.UninitializedObject, - -clang-analyzer-optin.cplusplus.VirtualCall, - -clang-analyzer-optin.mpi.MPI-Checker, - -clang-analyzer-optin.osx.OSObjectCStyleCast, - -clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker, - -clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker, - -clang-analyzer-optin.performance.GCDAntipattern, - -clang-analyzer-optin.performance.Padding, - -clang-analyzer-optin.portability.UnixAPI, - -clang-analyzer-osx.API, - -clang-analyzer-osx.MIG, - -clang-analyzer-osx.NumberObjectConversion, - -clang-analyzer-osx.OSObjectRetainCount, - -clang-analyzer-osx.ObjCProperty, - -clang-analyzer-osx.SecKeychainAPI, - -clang-analyzer-osx.cocoa.AtSync, - -clang-analyzer-osx.cocoa.AutoreleaseWrite, - -clang-analyzer-osx.cocoa.ClassRelease, - -clang-analyzer-osx.cocoa.Dealloc, - -clang-analyzer-osx.cocoa.IncompatibleMethodTypes, - -clang-analyzer-osx.cocoa.Loops, - -clang-analyzer-osx.cocoa.MissingSuperCall, - -clang-analyzer-osx.cocoa.NSAutoreleasePool, - -clang-analyzer-osx.cocoa.NSError, - -clang-analyzer-osx.cocoa.NilArg, - -clang-analyzer-osx.cocoa.NonNilReturnValue, - -clang-analyzer-osx.cocoa.ObjCGenerics, - -clang-analyzer-osx.cocoa.RetainCount, - -clang-analyzer-osx.cocoa.RunLoopAutoreleaseLeak, - -clang-analyzer-osx.cocoa.SelfInit, - -clang-analyzer-osx.cocoa.SuperDealloc, - -clang-analyzer-osx.cocoa.UnusedIvars, - -clang-analyzer-osx.cocoa.VariadicMethodTypes, - -clang-analyzer-osx.coreFoundation.CFError, - -clang-analyzer-osx.coreFoundation.CFNumber, - -clang-analyzer-osx.coreFoundation.CFRetainRelease, - -clang-analyzer-osx.coreFoundation.containers.OutOfBounds, - -clang-analyzer-osx.coreFoundation.containers.PointerSizedValues, - -clang-analyzer-security.FloatLoopCounter, - -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, - -clang-analyzer-security.insecureAPI.UncheckedReturn, - -clang-analyzer-security.insecureAPI.bcmp, - -clang-analyzer-security.insecureAPI.bcopy, - -clang-analyzer-security.insecureAPI.bzero, - -clang-analyzer-security.insecureAPI.decodeValueOfObjCType, - -clang-analyzer-security.insecureAPI.getpw, - -clang-analyzer-security.insecureAPI.gets, - -clang-analyzer-security.insecureAPI.mkstemp, - -clang-analyzer-security.insecureAPI.mktemp, - -clang-analyzer-security.insecureAPI.rand, - -clang-analyzer-security.insecureAPI.strcpy, - -clang-analyzer-security.insecureAPI.vfork, - -clang-analyzer-unix.API, - -clang-analyzer-unix.Malloc, - -clang-analyzer-unix.MallocSizeof, - -clang-analyzer-unix.MismatchedDeallocator, - -clang-analyzer-unix.Vfork, - -clang-analyzer-unix.cstring.BadSizeArg, - -clang-analyzer-unix.cstring.NullArg, - -clang-analyzer-valist.CopyToSelf, - -clang-analyzer-valist.Uninitialized, - -clang-analyzer-valist.Unterminated, - -clang-analyzer-webkit.NoUncountedMemberChecker, - -clang-analyzer-webkit.RefCntblBaseVirtualDtor, - -clang-analyzer-webkit.UncountedLambdaCapturesChecker, - -cppcoreguidelines-avoid-c-arrays, - -cppcoreguidelines-avoid-magic-numbers, - -cppcoreguidelines-c-copy-assignment-signature, - -cppcoreguidelines-explicit-virtual-functions, - -cppcoreguidelines-macro-to-enum, - -cppcoreguidelines-noexcept-destructor, - -cppcoreguidelines-noexcept-move-operations, - -cppcoreguidelines-noexcept-swap, - -cppcoreguidelines-non-private-member-variables-in-classes, - -cppcoreguidelines-use-default-member-init, - -fuchsia-header-anon-namespaces, - -google-readability-braces-around-statements, - -google-readability-function-size, - -google-readability-namespace-comments, - -hicpp-avoid-c-arrays, - -hicpp-avoid-goto, - -hicpp-braces-around-statements, - -hicpp-deprecated-headers, - -hicpp-explicit-conversions, - -hicpp-function-size, - -hicpp-invalid-access-moved, - -hicpp-member-init, - -hicpp-move-const-arg, - -hicpp-named-parameter, - -hicpp-new-delete-operators, - -hicpp-no-array-decay, - -hicpp-no-malloc, - -hicpp-noexcept-move, - -hicpp-special-member-functions, - -hicpp-static-assert, - -hicpp-undelegated-constructor, - -hicpp-uppercase-literal-suffix, - -hicpp-use-auto, - -hicpp-use-emplace, - -hicpp-use-equals-default, - -hicpp-use-equals-delete, - -hicpp-use-noexcept, - -hicpp-use-nullptr, - -hicpp-use-override, - -hicpp-vararg, - -llvm-else-after-return, - -llvm-qualified-auto' + -cert-con36-c, + -cert-con54-cpp, + -cert-dcl03-c, + -cert-dcl16-c, + -cert-dcl37-c, + -cert-dcl51-cpp, + -cert-dcl54-cpp, + -cert-dcl59-cpp, + -cert-err09-cpp, + -cert-err61-cpp, + -cert-exp42-c, + -cert-fio38-c, + -cert-flp37-c, + -cert-msc24-c, + -cert-msc30-c, + -cert-msc32-c, + -cert-msc33-c, + -cert-msc54-cpp, + -cert-oop11-cpp, + -cert-oop54-cpp, + -cert-pos44-c, + -cert-pos47-c, + -cert-sig30-c, + -cert-str34-c, + -clang-analyzer-core.BitwiseShift, + -clang-analyzer-core.CallAndMessage, + -clang-analyzer-core.DivideZero, + -clang-analyzer-core.NonNullParamChecker, + -clang-analyzer-core.NullDereference, + -clang-analyzer-core.StackAddressEscape, + -clang-analyzer-core.UndefinedBinaryOperatorResult, + -clang-analyzer-core.VLASize, + -clang-analyzer-core.uninitialized.ArraySubscript, + -clang-analyzer-core.uninitialized.Assign, + -clang-analyzer-core.uninitialized.Branch, + -clang-analyzer-core.uninitialized.CapturedBlockVariable, + -clang-analyzer-core.uninitialized.NewArraySize, + -clang-analyzer-core.uninitialized.UndefReturn, + -clang-analyzer-cplusplus.InnerPointer, + -clang-analyzer-cplusplus.Move, + -clang-analyzer-cplusplus.NewDelete, + -clang-analyzer-cplusplus.NewDeleteLeaks, + -clang-analyzer-cplusplus.PlacementNew, + -clang-analyzer-cplusplus.PureVirtualCall, + -clang-analyzer-cplusplus.StringChecker, + -clang-analyzer-deadcode.DeadStores, + -clang-analyzer-fuchsia.HandleChecker, + -clang-analyzer-nullability.NullPassedToNonnull, + -clang-analyzer-nullability.NullReturnedFromNonnull, + -clang-analyzer-nullability.NullableDereferenced, + -clang-analyzer-nullability.NullablePassedToNonnull, + -clang-analyzer-nullability.NullableReturnedFromNonnull, + -clang-analyzer-optin.cplusplus.UninitializedObject, + -clang-analyzer-optin.cplusplus.VirtualCall, + -clang-analyzer-optin.mpi.MPI-Checker, + -clang-analyzer-optin.osx.OSObjectCStyleCast, + -clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker, + -clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker, + -clang-analyzer-optin.performance.GCDAntipattern, + -clang-analyzer-optin.performance.Padding, + -clang-analyzer-optin.portability.UnixAPI, + -clang-analyzer-osx.API, + -clang-analyzer-osx.MIG, + -clang-analyzer-osx.NumberObjectConversion, + -clang-analyzer-osx.OSObjectRetainCount, + -clang-analyzer-osx.ObjCProperty, + -clang-analyzer-osx.SecKeychainAPI, + -clang-analyzer-osx.cocoa.AtSync, + -clang-analyzer-osx.cocoa.AutoreleaseWrite, + -clang-analyzer-osx.cocoa.ClassRelease, + -clang-analyzer-osx.cocoa.Dealloc, + -clang-analyzer-osx.cocoa.IncompatibleMethodTypes, + -clang-analyzer-osx.cocoa.Loops, + -clang-analyzer-osx.cocoa.MissingSuperCall, + -clang-analyzer-osx.cocoa.NSAutoreleasePool, + -clang-analyzer-osx.cocoa.NSError, + -clang-analyzer-osx.cocoa.NilArg, + -clang-analyzer-osx.cocoa.NonNilReturnValue, + -clang-analyzer-osx.cocoa.ObjCGenerics, + -clang-analyzer-osx.cocoa.RetainCount, + -clang-analyzer-osx.cocoa.RunLoopAutoreleaseLeak, + -clang-analyzer-osx.cocoa.SelfInit, + -clang-analyzer-osx.cocoa.SuperDealloc, + -clang-analyzer-osx.cocoa.UnusedIvars, + -clang-analyzer-osx.cocoa.VariadicMethodTypes, + -clang-analyzer-osx.coreFoundation.CFError, + -clang-analyzer-osx.coreFoundation.CFNumber, + -clang-analyzer-osx.coreFoundation.CFRetainRelease, + -clang-analyzer-osx.coreFoundation.containers.OutOfBounds, + -clang-analyzer-osx.coreFoundation.containers.PointerSizedValues, + -clang-analyzer-security.FloatLoopCounter, + -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, + -clang-analyzer-security.insecureAPI.UncheckedReturn, + -clang-analyzer-security.insecureAPI.bcmp, + -clang-analyzer-security.insecureAPI.bcopy, + -clang-analyzer-security.insecureAPI.bzero, + -clang-analyzer-security.insecureAPI.decodeValueOfObjCType, + -clang-analyzer-security.insecureAPI.getpw, + -clang-analyzer-security.insecureAPI.gets, + -clang-analyzer-security.insecureAPI.mkstemp, + -clang-analyzer-security.insecureAPI.mktemp, + -clang-analyzer-security.insecureAPI.rand, + -clang-analyzer-security.insecureAPI.strcpy, + -clang-analyzer-security.insecureAPI.vfork, + -clang-analyzer-unix.API, + -clang-analyzer-unix.Malloc, + -clang-analyzer-unix.MallocSizeof, + -clang-analyzer-unix.MismatchedDeallocator, + -clang-analyzer-unix.Vfork, + -clang-analyzer-unix.cstring.BadSizeArg, + -clang-analyzer-unix.cstring.NullArg, + -clang-analyzer-valist.CopyToSelf, + -clang-analyzer-valist.Uninitialized, + -clang-analyzer-valist.Unterminated, + -clang-analyzer-webkit.NoUncountedMemberChecker, + -clang-analyzer-webkit.RefCntblBaseVirtualDtor, + -clang-analyzer-webkit.UncountedLambdaCapturesChecker, + -cppcoreguidelines-avoid-c-arrays, + -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-c-copy-assignment-signature, + -cppcoreguidelines-explicit-virtual-functions, + -cppcoreguidelines-macro-to-enum, + -cppcoreguidelines-noexcept-destructor, + -cppcoreguidelines-noexcept-move-operations, + -cppcoreguidelines-noexcept-swap, + -cppcoreguidelines-non-private-member-variables-in-classes, + -cppcoreguidelines-use-default-member-init, + -fuchsia-header-anon-namespaces, + -google-readability-braces-around-statements, + -google-readability-function-size, + -google-readability-namespace-comments, + -hicpp-avoid-c-arrays, + -hicpp-avoid-goto, + -hicpp-braces-around-statements, + -hicpp-deprecated-headers, + -hicpp-explicit-conversions, + -hicpp-function-size, + -hicpp-invalid-access-moved, + -hicpp-member-init, + -hicpp-move-const-arg, + -hicpp-named-parameter, + -hicpp-new-delete-operators, + -hicpp-no-array-decay, + -hicpp-no-malloc, + -hicpp-noexcept-move, + -hicpp-special-member-functions, + -hicpp-static-assert, + -hicpp-undelegated-constructor, + -hicpp-uppercase-literal-suffix, + -hicpp-use-auto, + -hicpp-use-emplace, + -hicpp-use-equals-default, + -hicpp-use-equals-delete, + -hicpp-use-noexcept, + -hicpp-use-nullptr, + -hicpp-use-override, + -hicpp-vararg, + -llvm-else-after-return, + -llvm-qualified-auto' WarningsAsErrors: '*' FormatStyle: 'file' HeaderFilterRegex: '(include/)|(src/)' diff --git a/include/stdsharp/concepts/concepts.h b/include/stdsharp/concepts/concepts.h index 17c36e8..3f508b7 100644 --- a/include/stdsharp/concepts/concepts.h +++ b/include/stdsharp/concepts/concepts.h @@ -3,9 +3,11 @@ // #pragma once -#include #include +#include #include +#include +#include #include "../macros.h" #include "../namespace_alias.h" @@ -33,6 +35,9 @@ namespace stdsharp template concept const_ = std::is_const_v; + template + concept non_const = !const_; + template concept const_lvalue_ref = std::is_lvalue_reference_v && const_>; @@ -440,10 +445,7 @@ namespace stdsharp copy_assignable && // std::equality_comparable && // weakly_equality_comparable_with; -} -namespace stdsharp -{ template concept referenceable = requires(T&) { 0; }; diff --git a/include/stdsharp/memory/aligned.h b/include/stdsharp/memory/aligned.h index 158746d..b432c75 100644 --- a/include/stdsharp/memory/aligned.h +++ b/include/stdsharp/memory/aligned.h @@ -6,11 +6,12 @@ namespace stdsharp { inline constexpr struct align_fn { - template - requires(!const_) - auto - operator()(const std::size_t alignment, const std::size_t size, const std::span& span) - const noexcept + template + auto operator()( + const std::size_t alignment, + const std::size_t size, + const std::span& span + ) const noexcept { auto space = span.size_bytes(); void* void_ptr = span.data(); diff --git a/include/stdsharp/synchronizer.h b/include/stdsharp/synchronizer.h index 48aa8e8..8ba41f9 100644 --- a/include/stdsharp/synchronizer.h +++ b/include/stdsharp/synchronizer.h @@ -7,7 +7,8 @@ namespace stdsharp { - template + template + requires basic_lockable class synchronizer { public: @@ -18,7 +19,13 @@ namespace stdsharp synchronizer() = default; template - requires std::constructible_from + requires requires { + requires std::constructible_from; + requires std::default_initializable; + requires !requires { + [](const std::piecewise_construct_t, auto&&...) {}(std::declval()...); + }; + } explicit(sizeof...(Args) == 1) constexpr synchronizer(Args&&... args) // noexcept(nothrow_constructible_from && nothrow_default_initializable): value_(cpp_forward(args)...) @@ -35,6 +42,37 @@ namespace stdsharp ~synchronizer() = default; + private: + template + constexpr synchronizer( + ValueTuple&& value_tuple, + LockableTuple&& lockable_tuple, + std::index_sequence /*unused*/, + std::index_sequence /*unused*/ + ): + value_(cpo::get_element(cpp_forward(value_tuple))...), + lockable_(cpo::get_element(cpp_forward(lockable_tuple))...) + { + } + + public: + template + requires piecewise_constructible_from && + piecewise_constructible_from + constexpr synchronizer( + const std::piecewise_construct_t /*unused*/, + ValueTuple&& value_tuple, + LockableTuple&& lockable_tuple + ): + synchronizer( + cpp_forward(value_tuple), + cpp_forward(lockable_tuple), + std::make_index_sequence>>{}, + std::make_index_sequence>>{} + ) + { + } + #define STDSHARP_SYN_MEM(volatile_, ref) \ template \ constexpr void read( \ @@ -43,7 +81,7 @@ namespace stdsharp ) const volatile_ ref \ requires std::constructible_from, lock_type&, Args...> \ { \ - const std::shared_lock lock{lockable_, cpp_forward(args)...}; \ + const std::shared_lock lock{lockable_, cpp_forward(args)...}; \ invoke(cpp_forward(func), cpp_forward(*this).value_); \ } \ \ @@ -52,7 +90,7 @@ namespace stdsharp volatile_ ref \ requires std::constructible_from, lock_type&, Args...> \ { \ - const std::unique_lock lock{lockable_, cpp_forward(args)...}; \ + const std::unique_lock lock{lockable_, cpp_forward(args)...}; \ invoke(cpp_forward(func), cpp_forward(*this).value_); \ } diff --git a/include/stdsharp/type_traits/core_traits.h b/include/stdsharp/type_traits/core_traits.h index d761a98..9b41252 100644 --- a/include/stdsharp/type_traits/core_traits.h +++ b/include/stdsharp/type_traits/core_traits.h @@ -521,12 +521,37 @@ namespace stdsharp::details STDSHARP_NO_UNIQUE_ADDRESS T v; }; }; + + template< + typename T, + typename Tuple, + typename = std::make_index_sequence>> + struct piecewise_traits; + + template + struct piecewise_traits> + { + static constexpr auto constructible_from = + requires { requires std::constructible_from...>; }; + + static constexpr auto nothrow_constructible_from = requires { + requires std::is_nothrow_constructible_v...>; + }; + }; } namespace stdsharp { template using ebo_union = details::ebo_union::type; + + template + concept piecewise_constructible_from = // + details::piecewise_traits::constructible_from; + + template + concept piecewise_nothrow_constructible_from = // + details::piecewise_traits::nothrow_constructible_from; } namespace meta::extension