Skip to content

Commit 965194a

Browse files
authored
Merge pull request #757 from marcoffee/fix/clang-constexpr-et
Fix issue with temporaries when compiling constexpr expression templates with clang
2 parents e28ec3e + 3645c30 commit 965194a

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

include/boost/multiprecision/detail/number_base.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ struct expression_storage_base<T, true>
457457
};
458458

459459
template <class T>
460-
struct expression_storage : public expression_storage_base<T, boost::multiprecision::detail::is_arithmetic<T>::value>
460+
struct expression_storage : public expression_storage_base<T, boost::multiprecision::detail::is_arithmetic<T>::value || std::is_empty<T>::value>
461461
{};
462462

463463
template <class T>

test/Jamfile.v2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@ test-suite misc :
10621062
[ run constexpr_test_cpp_int_5.cpp : : : [ requires cxx14_constexpr cxx17_if_constexpr ] [ check-target-builds ../config//has_is_constant_evaluated : : <build>no ] ]
10631063
[ run constexpr_test_cpp_int_6.cpp : : : [ requires cxx14_constexpr cxx17_if_constexpr ] [ check-target-builds ../config//has_is_constant_evaluated : "<toolset>msvc:<cxxflags>-constexpr:steps10000000" <toolset>clang:<cxxflags>-fconstexpr-steps=268435456 : <build>no ] [ check-target-builds ../config//has_constexpr_limits : <cxxflags>-fconstexpr-ops-limit=268435456 ] ]
10641064
[ run constexpr_test_cpp_int_7.cpp : : : [ requires cxx14_constexpr cxx17_if_constexpr ] [ check-target-builds ../config//has_is_constant_evaluated : "<toolset>msvc:<cxxflags>-constexpr:steps10000000" <toolset>clang:<cxxflags>-fconstexpr-steps=268435456 : <build>no ] ]
1065+
[ run constexpr_test_cpp_int_8.cpp : : : [ requires cxx14_constexpr cxx17_if_constexpr ] [ check-target-builds ../config//has_is_constant_evaluated : : <build>no ] ]
10651066

10661067
[ compile test_nothrow_cpp_int.cpp ]
10671068
[ compile test_nothrow_cpp_rational.cpp ]

test/constexpr_test_cpp_int_8.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// (C) Copyright Marco Ribeiro 2026.
2+
// Use, modification and distribution are subject to the
3+
// Boost Software License, Version 1.0. (See accompanying file
4+
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
#include "constexpr_arithmetric_test.hpp"
7+
#include "boost/multiprecision/cpp_int.hpp"
8+
#include "test.hpp"
9+
10+
#if !defined(BOOST_MP_NO_CONSTEXPR_DETECTION) && !defined(DISABLE_TESTS)
11+
12+
int main()
13+
{
14+
namespace mp = boost::multiprecision;
15+
16+
using int512_et_off = mp::number<mp::cpp_int_backend<
17+
512, 512, mp::signed_magnitude, mp::unchecked, void
18+
>, mp::et_off>;
19+
20+
using int512_et_on = mp::number<mp::cpp_int_backend<
21+
512, 512, mp::signed_magnitude, mp::unchecked, void
22+
>, mp::et_on>;
23+
24+
static_assert(mp::abs(int512_et_off(-12345)) == 12345);
25+
static_assert(mp::conj(int512_et_off(100)) == 100);
26+
static_assert(mp::proj(int512_et_off(100)) == 100);
27+
static_assert(mp::powm(int512_et_off(-5), 2, 7) == 4);
28+
29+
static_assert(mp::abs(int512_et_on(-12345)) == 12345);
30+
static_assert(mp::conj(int512_et_on(100)) == 100);
31+
static_assert(mp::proj(int512_et_on(100)) == 100);
32+
static_assert(mp::powm(int512_et_on(-5), 2, 7) == 4);
33+
}
34+
#else
35+
int main() {}
36+
#endif
37+

0 commit comments

Comments
 (0)