Add __builtin_constant_p for gcc build without optimizations

This commit is contained in:
sha512sum 2024-07-07 03:58:42 +00:00
parent f7ecbd6d20
commit cfb5f82948
3 changed files with 5 additions and 7 deletions

View file

@ -3,8 +3,8 @@
#include <utempl/type_list.hpp> #include <utempl/type_list.hpp>
struct SomeStruct { struct SomeStruct {
constexpr SomeStruct(auto&& arg) { explicit constexpr SomeStruct(auto&& arg) {
arg.Method(42); arg.Method(42); // NOLINT
}; };
}; };
@ -15,15 +15,13 @@ struct Injector {
template <typename T, auto... Args> template <typename T, auto... Args>
inline constexpr auto Use() { inline constexpr auto Use() {
std::ignore = T{Args...}; std::ignore = __builtin_constant_p(T{Args...});
}; };
template <typename...> template <typename...>
consteval auto Ignore() {}; consteval auto Ignore() {};
auto main() -> int { auto main() -> int {
Ignore<decltype(Use<SomeStruct, Injector{}>())>(); Ignore<decltype(Use<SomeStruct, Injector{}>())>();
static_assert(std::is_same_v<decltype(Magic(utempl::loopholes::Getter<0>{})), utempl::TypeList<int>>); static_assert(std::is_same_v<decltype(Magic(utempl::loopholes::Getter<0>{})), utempl::TypeList<int>>);
}; };

View file

@ -6,5 +6,5 @@ check_required_components("@PROJECT_NAME@")
try_compile(loopholes_body_inject try_compile(loopholes_body_inject
SOURCES "${CMAKE_CURRENT_LIST_DIR}/check.cpp") SOURCES "${CMAKE_CURRENT_LIST_DIR}/check.cpp")
if(NOT loopholes_body_inject) if(NOT loopholes_body_inject)
message(FATAL_ERROR "The Compiler Doesn't Support Retrieval Of Information Via Loopholes. If You Are Using gcc, Enable Optimizations.") message(FATAL_ERROR "The Compiler Doesn't Support Retrieval Of Information Via Loopholes.")
endif() endif()

View file

@ -336,7 +336,7 @@ struct DependencyInfoKey {};
template <typename T, auto... Args> template <typename T, auto... Args>
inline constexpr auto Use() { inline constexpr auto Use() {
std::ignore = T{Args...}; std::ignore = __builtin_constant_p(T{Args...});
}; };
template <typename...> template <typename...>