diff options
-rw-r--r-- | clang/lib/AST/ASTImporter.cpp | 9 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 10 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 9 | ||||
-rw-r--r-- | clang/test/Misc/ast-dump-attr.cpp | 17 | ||||
-rw-r--r-- | clang/test/Sema/anonymous-struct-union.c | 10 |
5 files changed, 43 insertions, 12 deletions
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index ca7ab63c96f..1627e477f95 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -2958,9 +2958,12 @@ Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { } IndirectFieldDecl *ToIndirectField = IndirectFieldDecl::Create( - Importer.getToContext(), DC, - Loc, Name.getAsIdentifierInfo(), T, - NamedChain, D->getChainingSize()); + Importer.getToContext(), DC, Loc, Name.getAsIdentifierInfo(), T, + NamedChain, D->getChainingSize()); + + for (const auto *Attr : D->attrs()) + ToIndirectField->addAttr(Attr->clone(Importer.getToContext())); + ToIndirectField->setAccess(D->getAccess()); ToIndirectField->setLexicalDeclContext(LexicalDC); Importer.Imported(D, ToIndirectField); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 22a7e732c50..65eafd5a3c2 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3723,10 +3723,12 @@ static bool InjectAnonymousStructOrUnionMembers(Sema &SemaRef, Scope *S, for (unsigned i = 0; i < Chaining.size(); i++) NamedChain[i] = Chaining[i]; - IndirectFieldDecl* IndirectField = - IndirectFieldDecl::Create(SemaRef.Context, Owner, VD->getLocation(), - VD->getIdentifier(), VD->getType(), - NamedChain, Chaining.size()); + IndirectFieldDecl *IndirectField = IndirectFieldDecl::Create( + SemaRef.Context, Owner, VD->getLocation(), VD->getIdentifier(), + VD->getType(), NamedChain, Chaining.size()); + + for (const auto *Attr : VD->attrs()) + IndirectField->addAttr(Attr->clone(SemaRef.Context)); IndirectField->setAccess(AS); IndirectField->setImplicit(); diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 274105d532a..ec8c08ddf53 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -653,11 +653,12 @@ Decl *TemplateDeclInstantiator::VisitIndirectFieldDecl(IndirectFieldDecl *D) { } QualType T = cast<FieldDecl>(NamedChain[i-1])->getType(); - IndirectFieldDecl* IndirectField - = IndirectFieldDecl::Create(SemaRef.Context, Owner, D->getLocation(), - D->getIdentifier(), T, - NamedChain, D->getChainingSize()); + IndirectFieldDecl *IndirectField = IndirectFieldDecl::Create( + SemaRef.Context, Owner, D->getLocation(), D->getIdentifier(), T, + NamedChain, D->getChainingSize()); + for (const auto *Attr : D->attrs())
+ IndirectField->addAttr(Attr->clone(SemaRef.Context));
IndirectField->setImplicit(D->isImplicit()); IndirectField->setAccess(D->getAccess()); diff --git a/clang/test/Misc/ast-dump-attr.cpp b/clang/test/Misc/ast-dump-attr.cpp index 1aa6adf79b0..446f0fa692f 100644 --- a/clang/test/Misc/ast-dump-attr.cpp +++ b/clang/test/Misc/ast-dump-attr.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-pc-linux -std=c++11 -ast-dump -ast-dump-filter Test %s | FileCheck --strict-whitespace %s +// RUN: %clang_cc1 -triple x86_64-pc-linux -std=c++11 -Wno-deprecated-declarations -ast-dump -ast-dump-filter Test %s | FileCheck --strict-whitespace %s int TestLocation __attribute__((unused)); @@ -135,3 +135,18 @@ void func() { // CHECK-NOT: NoReturnAttr // CHECK: CXXConversionDecl{{.*}}operator void (*)() __attribute__((noreturn)) } + +namespace PR20930 { +struct S { + struct { int Test __attribute__((deprecated)); }; + // CHECK: FieldDecl{{.*}}Test 'int' + // CHECK-NEXT: DeprecatedAttr +}; + +void f() { + S s; + s.Test = 1; + // CHECK: IndirectFieldDecl{{.*}}Test 'int' + // CHECK: DeprecatedAttr +} +} diff --git a/clang/test/Sema/anonymous-struct-union.c b/clang/test/Sema/anonymous-struct-union.c index 26dbeb87f5f..652383eabb7 100644 --- a/clang/test/Sema/anonymous-struct-union.c +++ b/clang/test/Sema/anonymous-struct-union.c @@ -108,3 +108,13 @@ struct s { struct { int i; }; int a[]; }; + +// PR20930 +struct s3 { + struct { int A __attribute__((deprecated)); }; // expected-note {{'A' has been explicitly marked deprecated here}} +}; + +void deprecated_anonymous_struct_member(void) { + struct s3 s; + s.A = 1; // expected-warning {{'A' is deprecated}} +} |