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

Compilation failed on Traits.hpp with XCode 16 #10

Open
ouj opened this issue Sep 27, 2024 · 1 comment
Open

Compilation failed on Traits.hpp with XCode 16 #10

ouj opened this issue Sep 27, 2024 · 1 comment

Comments

@ouj
Copy link

ouj commented Sep 27, 2024

XCode16 have a stricter static assert

error: static assertion failed due to requirement '!__is_same(float, float)': std::declval can only be used in an unevaluated context. It's likely that your current usage is trying to extract a value from the function.

https://github.com/gavv/libASPL/blob/main/src/Traits.hpp

╭─    ~/work/loomhq/libASPL   main ··················································································································································· ✘ 2   3s  12:17:47 PM 
╰─ make                                                                                                                                                                                                           (base)
mkdir -p build/Release
cd build/Release && cmake -Wno-dev -DCMAKE_BUILD_TYPE=Release ../..
-- Detected version from git: 3.1.0
-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/jou2/work/loomhq/libASPL/build/Release
cd build/Release && make -j12
[  4%] Building CXX object CMakeFiles/libASPL.dir/src/Plugin.g.cpp.o
[  8%] Building CXX object CMakeFiles/libASPL.dir/src/Driver.cpp.o
[ 12%] Building CXX object CMakeFiles/libASPL.dir/src/Storage.cpp.o
[ 16%] Building CXX object CMakeFiles/libASPL.dir/src/Uid.cpp.o
[ 24%] Building CXX object CMakeFiles/libASPL.dir/src/Strings.cpp.o
[ 24%] Building CXX object CMakeFiles/libASPL.dir/src/Convert.cpp.o
[ 28%] Building CXX object CMakeFiles/libASPL.dir/src/Tracer.cpp.o
[ 32%] Building CXX object CMakeFiles/libASPL.dir/src/Strings.g.cpp.o
[ 36%] Building CXX object CMakeFiles/libASPL.dir/src/Client.cpp.o
[ 40%] Building CXX object CMakeFiles/libASPL.dir/src/Dispatcher.cpp.o
[ 48%] Building CXX object CMakeFiles/libASPL.dir/src/VolumeCurve.cpp.o
[ 48%] Building CXX object CMakeFiles/libASPL.dir/src/VolumeControl.g.cpp.o
In file included from /Users/jou2/work/loomhq/libASPL/src/VolumeControl.g.cpp:10:
In file included from /Users/jou2/work/loomhq/libASPL/include/aspl/VolumeControl.hpp:9:
In file included from /Users/jou2/work/loomhq/libASPL/include/aspl/Direction.hpp:9:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:28:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/usr/include/c++/v1/math.h:359:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/usr/include/c++/v1/__math/copysign.h:15:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/usr/include/c++/v1/__type_traits/promote.h:15:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/usr/include/c++/v1/__utility/declval.h:31:17: error: static assertion failed due to requirement '!__is_same(float, float)': std::declval can only be used in an unevaluated context. It's likely that your current usage is trying to extract a value from the function.
   31 |   static_assert(!__is_same(_Tp, _Tp),
      |                 ^~~~~~~~~~~~~~~~~~~~
/Users/jou2/work/loomhq/libASPL/src/Traits.hpp:34:21: note: in instantiation of function template specialization 'std::declval<float>' requested here
   34 |         return std::declval<Return>();
      |                     ^
1 error generated.
make[3]: *** [CMakeFiles/libASPL.dir/src/VolumeControl.g.cpp.o] Error 1
make[3]: *** Waiting for unfinished jobs....
In file included from /Users/jou2/work/loomhq/libASPL/src/Plugin.g.cpp:10:
In file included from /Users/jou2/work/loomhq/libASPL/include/aspl/Plugin.hpp:9:
In file included from /Users/jou2/work/loomhq/libASPL/include/aspl/Device.hpp:9:
In file included from /Users/jou2/work/loomhq/libASPL/include/aspl/Client.hpp:9:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:28:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/usr/include/c++/v1/math.h:359:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/usr/include/c++/v1/__math/copysign.h:15:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/usr/include/c++/v1/__type_traits/promote.h:15:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/usr/include/c++/v1/__utility/declval.h:31:17: error: static assertion failed due to requirement '!__is_same(const std::string &, const std::string &)': std::declval can only be used in an unevaluated context. It's likely that your current usage is trying to extract a value from the function.
   31 |   static_assert(!__is_same(_Tp, _Tp),
      |                 ^~~~~~~~~~~~~~~~~~~~
/Users/jou2/work/loomhq/libASPL/src/Traits.hpp:67:21: note: in instantiation of function template specialization 'std::declval<const std::string &>' requested here
   67 |         return std::declval<nth_argument_t<Args...>>();
      |                     ^
1 error generated.
make[3]: *** [CMakeFiles/libASPL.dir/src/Plugin.g.cpp.o] Error 1
make[2]: *** [CMakeFiles/libASPL.dir/all] Error 2
make[1]: *** [all] Error 2
make: *** [release_build] Error 2
@ouj
Copy link
Author

ouj commented Sep 27, 2024

Consulted with AI. This is the proposed fix:

// Copyright (c) libASPL authors
// Licensed under MIT

#pragma once

#include <tuple>
#include <type_traits>
#include <vector>

namespace aspl {

template <typename T>
struct is_vector : public std::false_type
{
};

template <typename T, typename A>
struct is_vector<std::vector<T, A>> : public std::true_type
{
};

template <typename Func>
class method_return_type
{
    template <typename Class, typename Return, typename... Args>
    static Return return_of(Return (Class::*)(Args...));

    template <typename Class, typename Return, typename... Args>
    static Return return_of(Return (Class::*)(Args...) const);

    template <typename Class, typename Return, typename... Args>
    static Return return_of(Return (Class::*)(Args...) const volatile);

public:
    using type = std::remove_cv_t<std::remove_reference_t<decltype(return_of(std::declval<Func>()))>>;
};

template <typename Method>
using method_return_type_t = typename method_return_type<Method>::type;

template <typename Func, size_t ArgIndex>
class method_argument_type
{
    template <typename... Args>
    using nth_argument_t = typename std::tuple_element<ArgIndex, std::tuple<Args...>>::type;

    template <typename Class, typename Return, typename... Args>
    static nth_argument_t<Args...> nth_argument_of(Return (Class::*)(Args...));

    template <typename Class, typename Return, typename... Args>
    static nth_argument_t<Args...> nth_argument_of(Return (Class::*)(Args...) const);

    template <typename Class, typename Return, typename... Args>
    static nth_argument_t<Args...> nth_argument_of(Return (Class::*)(Args...) const volatile);

public:
    using type = std::remove_cv_t<std::remove_reference_t<decltype(nth_argument_of(std::declval<Func>()))>>;
};

template <typename Method, size_t ArgIndex>
using method_argument_type_t = typename method_argument_type<Method, ArgIndex>::type;

} // namespace aspl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant