Suppose we have the following program:
template <class T, T n1, T n2>
struct Probe {
static const int which = 1;
};
template <class T, T n>
struct Probe<T, n, n> {
static const int which = 2;
};
int i = 123;
const int myQuestion = Probe<int&, i, i>::which;
I am pretty sure, that myQuestion
should be 2
regardless of the version of C++ standard, but compilers disagree upon it. MSVC and clang say that it is 2
until C++14, and 1
since C++17. See the demo. What is the truth?
My investigation so far: