Clang accepts invalid program involving static_cast from class type to const bool& with conversion operator
The following invalid program is accepted by clang. Demo
struct C {
explicit operator bool() const {
return true;
}
};
int main() {
C c;
auto b = static_cast<const bool &>(c);//accepted by clang only
}
@llvm/issue-subscribers-clang-frontend
Author: Anoop Rana (ranaanoop)
struct C {
explicit operator bool() const {
return true;
}
};
int main() {
C c;
auto b = static_cast<const bool &>(c);//accepted by clang only
}
I believe this is direct-initialization and so explicit conversion are allowd: https://eel.is/c++draft/over.match.ref#1.1
So I believe clang is correct and maybe this gcc bug report is related: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83615
Do I understand it correctly that [over.match.ref]/1.1 requires the conversion function to return an lvalue reference in this case (of initializing an lvalue reference)?
Do I understand it correctly that [over.match.ref]/1.1 requires the conversion function to return an lvalue reference in this case (of initializing an lvalue reference)?
https://cplusplus.github.io/CWG/issues/2919.html