llvm-project
llvm-project copied to clipboard
clang does not support initializing constant reference member with literal
The following simple test is currently rejected by clang:
struct test {
test() : x(0) {}
const int &x;
} ;
Assigning a temporary value to a corresponding constant reference variable is allowed in C++. Accordingly, the test should be well-formed.
Both GCC and MSVC accept it:
@llvm/issue-subscribers-clang-frontend
Author: Raki (Ming-3364)
The following simple test is currently rejected by clang:
struct test {
test() : x(0) {}
const int &x;
} ;
Assigning a temporary value to a corresponding constant reference variable is allowed in C++. Accordingly, the test should be well-formed.
Both GCC and MSVC accept it:
This example violates https://eel.is/c++draft/class.base.init#8; clang is correct to reject it.