From cdbd140e7a9e496e876eac0bbc57a2bb9ca5ab0f Mon Sep 17 00:00:00 2001 From: puerling Date: Tue, 6 Aug 2024 15:46:18 +0200 Subject: [PATCH] fix: calling `hasInteraction()` though an instance is not `constexpr` * clang identified the call to `hasInteraction()` as not being a constant expression. * `Hamiltonian::hasInteraction()` being a `constexpr` static member function might not be a constant expression when invoked through an instance of a `Hamiltonian` object. Accessing it through the type by using `decltype` is guaranteed to work. --- core/include/engine/common/Hamiltonian.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/include/engine/common/Hamiltonian.hpp b/core/include/engine/common/Hamiltonian.hpp index fe648c826..452efc8ed 100644 --- a/core/include/engine/common/Hamiltonian.hpp +++ b/core/include/engine/common/Hamiltonian.hpp @@ -626,7 +626,8 @@ class HamiltonianVariant : public TypeTraits template [[nodiscard]] bool hasInteraction() { - return std::visit( []( auto & h ) { return h.template hasInteraction(); }, hamiltonian ); + return std::visit( + []( auto & h ) { return std::decay_t::template hasInteraction(); }, hamiltonian ); }; template @@ -641,7 +642,7 @@ class HamiltonianVariant : public TypeTraits return std::visit( []( const auto & h ) -> const typename T::Data * { - if constexpr( h.template hasInteraction() ) + if constexpr( std::decay_t::template hasInteraction() ) return &h.template data(); else return nullptr; @@ -655,7 +656,7 @@ class HamiltonianVariant : public TypeTraits return std::visit( []( const auto & h ) -> const typename T::Cache * { - if constexpr( h.template hasInteraction() ) + if constexpr( std::decay_t::template hasInteraction() ) return &h.template cache(); else return nullptr; @@ -670,7 +671,7 @@ class HamiltonianVariant : public TypeTraits [this, data = typename T::Data( std::forward( args )... )]( auto & h ) mutable -> std::optional { - if constexpr( h.template hasInteraction() ) + if constexpr( std::decay_t::template hasInteraction() ) return h.template set_data( std::move( data ) ); else return fmt::format(