I am aware that once a reference is bound to an object it cannot be changed.
Therefore making the reference itself const (unlike a reference to a const object) cannot have any practical meaning.
Nevertheless I am wondering whether it is valid, because of a discrepenacy between compilers.
The following code is accepted by MSVC (though with a warning), but rejected by GCC and clang:
int main()
{
int a = 5;
[[maybe_unused]] int& const ref1 = a;
}
Live demo
Is MSVC right to accept it ?
1