Why passing argument by const reference always means the object is ODR-used? I understand, because Standard defines it this way, but why didn't it make exception at least for integral constants?
For example (my own example from the answer several hours ago):
struct T {
static constexpr int i = 42;
};
void check(const int& z);
int main() {
check(T::i); // <- 1
check(42); // <- 2
}
Line (1)
will triger an error at link time - standard considers it to be ODR-using of T::i
, and no definition is in sight. However, standard has no problem with example (2)
. And since (2)
has to work, why can't (1)
work for intgeral constexpr
? I realize that generally you need to take an address of the object to pass it by reference, but certainly not in case of numeric literals. Why wouldn't standard craft the exception for some constexpr
types?
Is it simply to avoid too many exceptions in the standard? But I see allowing usage as above as very beneficial! Is there anything else I fail to see?