[PATCH] D155895: Anonymous unions should be transparent wrt `[[clang::trivial_abi]]`.

Ɓukasz Anforowicz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 20 15:13:47 PDT 2023


lukasza added inline comments.


================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:10299
 
   if (!HasNonDeletedCopyOrMoveConstructor()) {
     PrintDiagAndRemoveAttr(0);
----------------
I tried to change this condition to `!RD.isAnonymousStructOrUnion() && !HasNonDeletedCopyOrMoveConstructor()` but it seems that at this point `isAnonymousStructOrUnion` doesn't yet work because `setAnonymousStructOrUnion` is called at a later point.


================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:10350
   }
 }
 
----------------
Alternative fix I've considered:
1.1. `setHasTrivialSpecialMemberForCall` for anonymous unions *if* their `DeclContext` is trivial.
1.2. Don't check `!HasNonDeletedCopyOrMoveConstructor()` for anonymous unions.

I don't know how to do 1.1 - this seems like a chicken-and-egg problem.  We can't know if `DeclContext` is trivial until we check `checkIllFormedTrivialABIStruct`, but when `checkIllFormedTrivialABIStruct` checks fields it requires that the triviality of the anonymous union is already known.

I don't know how to do 1.2 - changing the condition above to `!RD.isAnonymousStructOrUnion() && !HasNonDeletedCopyOrMoveConstructor()` doesn't work because at that point `isAnonymousStructOrUnion` doesn't yet work because `setAnonymousStructOrUnion` is called at a later point.




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155895/new/

https://reviews.llvm.org/D155895



More information about the cfe-commits mailing list