"function call must have constant value in constant expression"

I have the following code:

constexpr unsigned long long power_function(const unsigned long long prime, const unsigned long long iterations) {
    return iterations > 0 ? prime * power_function(prime, iterations - 1) : prime;
}

/* Inside my Class Definition*/

private:
    static constexpr unsigned long long prime = power_function(-363, 1'000'000); //Error occurs here

IntelliSense complains that it is power_functionused incorrectly. But for my life I can’t understand what the problem is. I am using Visual Studio 2015, FYI.

Error messages:

Error   C2131   expression did not evaluate to a constant   Basic Server    c:\<snip>   28  
Error   C2131   expression did not evaluate to a constant   Basic Server    c:\<snip>   33  

line 28 corresponds to the line where the return function is, and line 33 corresponds to the line where constexpr is defined.

+4
source share
1 answer

gcc clang 512 constexpr. constexpr (++ Standard 7.1.5 subsec. 2), . 512 , . 512 constexpr , (. B [implimits] 2.38 ).

Visual Studio, .

+3

Source: https://habr.com/ru/post/1628160/


All Articles