Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3026

When is a constexpr function not constexpr?

$
0
0
Consider
Code:

constexpr int fc(int i)
{
        return i * 3;
}

....
        fc(4);

        int c = 8;
        fc(c);

fc(4) should be evaluated at compile time because the argument to fc is known at compile time. However fc(c) will be evaluated at run-time.

What would be nice is if there is a way to produce a compiler warning when a function defined as constexpr is not able to be evaluated at compile-time but is evaluated at run-time. Is this possible somehow?

Viewing all articles
Browse latest Browse all 3026

Trending Articles