[clang] [clang] Improve bit-field in ref NTTP diagnostic (PR #71077)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 3 00:51:54 PST 2023
================
@@ -5992,6 +5992,15 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From,
/*InOverloadResolution=*/false,
/*AllowObjCWritebackConversion=*/false,
/*AllowExplicit=*/false);
+
+ // TryCopyInitialization returns incorrect info for attempts to bind reference
+ // to bit-field due to C++ [over.ics.ref]p4, so check it here.
+ if (From->refersToBitField() && T.getTypePtr()->isReferenceType()) {
+ return S.Diag(From->getBeginLoc(),
+ diag::err_reference_bind_to_bitfield_in_cce)
+ << From->getSourceRange();
+ }
----------------
cor3ntin wrote:
I think the wording that makes it not a constant expression is
> A [converted constant expression](https://eel.is/c++draft/expr.const#def:expression,converted_constant) of type T is an expression, implicitly converted to type T, where the converted expression is a constant expression [...] where the reference binding (if any) binds directly. Bitfields don't bind directly.
It might be worth saying that in the comment
https://github.com/llvm/llvm-project/pull/71077
More information about the cfe-commits
mailing list