C++
x
1
consteval int sqr(int n) { return n*n; }
2
constexpr int r = sqr(100); // Okay.
3
int x = 100; int r2 = sqr(x); // Error: Call does not produce a constant
4
$ g++ prog.cc -Wall -Wextra -std=c++2b
Start
prog.cc:3:27: error: the value of 'x' is not usable in a constant expression 3 | int x = 100; int r2 = sqr(x); // Error: Call does not produce a constant | ^ prog.cc:3:5: note: 'int x' is not const 3 | int x = 100; int r2 = sqr(x); // Error: Call does not produce a constant | ^
1
Finish