Page MenuHomePhabricator

[Sema][C] members of anonymous struct inherit QualType
AbandonedPublic

Authored by nickdesaulniers on Jan 25 2021, 4:20 PM.

Details

Summary

When declaring an anonymous struct with const or volatile
qualifiers, ensure the members of that anonymous struct are created with
that qualifier.

GCC behaves this way, and WG14 is currently discussing this behavior.

See also:

Diff Detail

Event Timeline

nickdesaulniers requested review of this revision.Jan 25 2021, 4:20 PM
nickdesaulniers created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2021, 4:20 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
clang/lib/Sema/SemaDecl.cpp
5179

Maybe there's a way to have Context.getTypeDeclType return the qualified type here? (I couldn't find a way, but only looked today).

I know we don't have to deal with restrict because that qualifies a pointer (so there's no way to use it with an anonymous struct), but are there others? There's DeclSpec::TQ_unaligned (which has no corresponding qualifier in Qualifiers::TQ despite the comment about keeping them in sync). Similarly, what about:

struct S {
  _Atomic struct {
    int i;
  };
}

void foo(void) {
  struct S s;
  s.i = 12; // Is this an atomic assignment?
}

Further, do we have to worry about things which are not type specifiers but still impact the declaration, like various type attributes?

clang/test/AST/ast-dump-decl.c
132

This looks wrong to me -- I would have assumed the type would be const int and not int, which would match the behavior if the type was directly qualified: https://godbolt.org/

nickdesaulniers abandoned this revision.May 9 2022, 12:05 PM
clang/test/AST/ast-dump-decl.c
132

Sorry, that godbolt link appears to be malformed (missing unique link)?

Herald added a project: Restricted Project. · View Herald TranscriptMay 9 2022, 12:05 PM