diff options
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 59539566e7d..d102cdf55dd 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -10144,6 +10144,27 @@ TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, QualType T, if (!Context.hasSameType(T, Context.getTagDeclType(tagFromDeclSpec))) break; + // If we've already computed linkage for the anonymous tag, then + // adding a typedef name for the anonymous decl can change that + // linkage, which might be a serious problem. Diagnose this as + // unsupported and ignore the typedef name. TODO: we should + // pursue this as a language defect and establish a formal rule + // for how to handle it. + if (tagFromDeclSpec->hasLinkageBeenComputed()) { + Diag(D.getIdentifierLoc(), diag::err_typedef_changes_linkage); + + SourceLocation tagLoc = D.getDeclSpec().getTypeSpecTypeLoc(); + tagLoc = Lexer::getLocForEndOfToken(tagLoc, 0, getSourceManager(), + getLangOpts()); + + llvm::SmallString<40> textToInsert; + textToInsert += ' '; + textToInsert += D.getIdentifier()->getName(); + Diag(tagLoc, diag::note_typedef_changes_linkage) + << FixItHint::CreateInsertion(tagLoc, textToInsert); + break; + } + // Otherwise, set this is the anon-decl typedef for the tag. tagFromDeclSpec->setTypedefNameForAnonDecl(NewTD); break; |