From a27d47bfae8c231891919c00ec2dfc92c59d764f Mon Sep 17 00:00:00 2001 From: Dan Katz Date: Wed, 17 Jul 2024 09:22:33 -0400 Subject: [PATCH] Disallow splicing of unnamed bit-fields. Closes issue #76. --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/lib/Sema/SemaReflect.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index fc7491fbcc3f9a..826bf8a5595fd5 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3132,6 +3132,8 @@ def err_splice_global_scope_as_namespace : Error< def err_member_access_splice_not_class_member : Error< "use of splice as qualified member access requires the reflection to be a " "member of a class">; +def err_splice_unnamed_bit_field : Error< + "cannot splice a reflection of an unnamed bit-field">; def err_unsupported_splice_kind : Error< "splicing %0 %select{as template arguments is|is}1 %select{not|not yet}2 " "%select{supported|implemented}2">; diff --git a/clang/lib/Sema/SemaReflect.cpp b/clang/lib/Sema/SemaReflect.cpp index e11d95e8aa64c8..380e9afea6e99c 100644 --- a/clang/lib/Sema/SemaReflect.cpp +++ b/clang/lib/Sema/SemaReflect.cpp @@ -816,6 +816,12 @@ ExprResult Sema::BuildReflectionSpliceExpr( return ExprError(); } + if (auto *FD = dyn_cast(TheDecl); + FD && FD->isUnnamedBitField()) { + Diag(Operand->getExprLoc(), diag::err_splice_unnamed_bit_field); + return ExprError(); + } + // Create a new DeclRefExpr, since the operand of the reflect expression // was parsed in an unevaluated context (but a splice expression is not // necessarily, and frequently not, in such a context).