See D84656 for the background on NamedDecl::printName.
This patch overloads NamedDecl::printName for VarDecl, FieldDecl ,RecordDecl and EnumDecl to provide a more user-friendly name in diagnostics for unnamed entities. We try to only use the term "anonymous" when we have an anonymous struct or union; otherwise we use the term "unnamed".
There is one little tweak we need to make to Sema::BuildAnonymousStructOrUnion: we mark the record as being anonymous as early as possible. This is to ensure that diagnostics emitted here will use the term "anonymous".
This pattern is happening a bunch too.... Does it deserve some function? Perhaps a function that either takes Policy, or a member of Policy to get the formatting open-tick or close-tick?