Błąd kompilatora C3615Compiler Error C3615
Funkcja constexpr "Function" nie może skutkować wyrażeniem stałymconstexpr function 'function' cannot result in a constant expression
Nie można ocenić funkcji funkcji w constexpr
czasie kompilacji.The function function could not be evaluated as constexpr
at compile time. Aby było możliwe constexpr
, funkcja może wywołać tylko inne constexpr
funkcje.To be constexpr
, a function can only call other constexpr
functions.
PrzykładExample
Program Visual Studio 2017 poprawnie zgłasza błąd, gdy operand po lewej stronie operacji oceniania warunkowego jest nieprawidłowy w constexpr
kontekście.Visual Studio 2017 correctly raises an error when the left-hand operand of a conditionally evaluating operation is not valid in a constexpr
context. Poniższy kod kompiluje się w programie Visual Studio 2015, ale nie w programie Visual Studio 2017.The following code compiles in Visual Studio 2015 but not in Visual Studio 2017.
// C3615.cpp
// Compile with: /c
template<int N>
struct myarray
{
int size() const { return N; }
};
constexpr bool f(const myarray<1> &arr)
{
return arr.size() == 10 || arr.size() == 11; // C3615 starting in Visual Studio 2017
}
Aby rozwiązać ten problem, należy zadeklarować array::size()
funkcję jako constexpr
lub usunąć constexpr
kwalifikator z elementu f
.To fix this issue, either declare the array::size()
function as constexpr
or remove the constexpr
qualifier from f
.