[clang] [clang] Add clang::preferred_type attribute for bitfields (PR #69104)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 20 12:15:36 PDT 2023


================
@@ -5910,6 +5910,51 @@ static void handleBuiltinAliasAttr(Sema &S, Decl *D,
   D->addAttr(::new (S.Context) BuiltinAliasAttr(S.Context, AL, Ident));
 }
 
+static void handlePreferredTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  if (!AL.hasParsedType()) {
+    S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
+    return;
+  }
+
+  TypeSourceInfo *ParmTSI = nullptr;
+  QualType QT = S.GetTypeFromParser(AL.getTypeArg(), &ParmTSI);
+  QT->getAsTagDecl()->setCompleteDefinitionRequired();
----------------
AaronBallman wrote:

I think we want a different approach here. If we decide to do non-integral/enum types right now, I think we want to call `Sema::RequireCompleteType()` on the given type. This will then diagnose uses of types like `void` or `int[]` as well as forward declarations. Losing forward declarations is a bit sad (because it could be completed later), but I think we can relax this restriction in the future as we find uses.

https://github.com/llvm/llvm-project/pull/69104


More information about the cfe-commits mailing list