diff options
author | John McCall <rjmccall@apple.com> | 2014-01-30 01:12:53 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2014-01-30 01:12:53 +0000 |
commit | 2575d8805927b789f9f19a4a7ac5ce3fb2742c08 (patch) | |
tree | e3d4027ea109a30cc6d55aff05a9b9bab135752d /clang/lib/Sema/SemaDecl.cpp | |
parent | a900d1cf4a2901464d9da3662eba9938edfe09f1 (diff) | |
download | bcm5719-llvm-2575d8805927b789f9f19a4a7ac5ce3fb2742c08.tar.gz bcm5719-llvm-2575d8805927b789f9f19a4a7ac5ce3fb2742c08.zip |
Diagnose typedef names for linkage purposes that would change
a previously-computed linkage as an unsupportable error condition.
Per discussion on cfe-commits, this appears to be a
difficult-to-resolve flaw in our implementation approach;
we may pursue this as a language defect, but for now it's
better to diagnose it as unsupported than to produce
inconsistent results (or assertions). Anything that we can
do to limit how often this diagnostic fires, such as the
changes in r200380, is probably for the best, though.
llvm-svn: 200438
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; |