[clang] [C23] Implement WG14 N3037 (PR #132939)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 26 05:18:22 PDT 2025


================
@@ -1496,9 +1615,37 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
     return false;
   }
 
-  if (Field1->isBitField())
-    return IsStructurallyEquivalent(Context, Field1->getBitWidth(),
-                                    Field2->getBitWidth());
+  if ((Field1->isBitField() || Field2->isBitField()) &&
+      !IsStructurallyEquivalent(Context, Field1->getBitWidth(),
+                                Field2->getBitWidth())) {
+    if (Context.Complain) {
+      auto DiagNote = [&](const FieldDecl *FD,
+                          DiagnosticBuilder (
+                              StructuralEquivalenceContext::*Diag)(
+                              SourceLocation, unsigned)) {
+        if (FD->isBitField()) {
+          std::string Str;
+          llvm::raw_string_ostream OS(Str);
+          PrintingPolicy Policy(Context.LangOpts);
+          FD->getBitWidth()->printPretty(OS, nullptr, Policy);
----------------
AaronBallman wrote:

Good question! That interface asserts if the width is invalid whereas the `printPretty()` interface will still emit output. I went back and forth on which way to go (I wasn't able to come up with a test case where `getBitWidthValue()` would trigger an assertion, but I still wasn't comfortable going that route). I can switch if you think it's worth it.

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


More information about the cfe-commits mailing list