Carucel
Carucel

Reputation: 481

A "constexpr" expression that takes too long

The following code does not compile in visual C++, because the "expression did not evaluate to a constant".

constexpr auto func() {
    for (unsigned long long i = 1; i < 10000000UL; ++i);
    return 123;
}
constexpr auto f = func();

In general, expressions that take too long to compute, cannot be made constexpr. Is it possible to give the compiler more time to evaluate such 'difficult' constexpressions?

Upvotes: 0

Views: 109

Answers (1)

Carucel
Carucel

Reputation: 481

The option /constexpr:steps is exactly the option that describes how long the compiler can think about constexpressions.

Upvotes: 1

Related Questions