summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-04-17 22:04:20 +0000
committerChris Lattner <sabre@nondot.org>2009-04-17 22:04:20 +0000
commit2581fc3fa98e369cce35684a576ec59cb7cabe83 (patch)
treeffd875e37175b652de0af7f018198b184f94c533 /clang/lib
parentba6e55737825046a5e1dff82d54a0745f11c0796 (diff)
downloadbcm5719-llvm-2581fc3fa98e369cce35684a576ec59cb7cabe83.tar.gz
bcm5719-llvm-2581fc3fa98e369cce35684a576ec59cb7cabe83.zip
tweak redefinition of a typedef a bit to fix a couple of problems:
1. We had logic in sema to decide whether or not to emit the error based on manually checking whether in a system header file. 2. we were allowing redefinitions of typedefs in class scope in C++ if in header file. 3. there was no way to force typedef redefinitions to be accepted by the C compiler, which annoys me when stripping linemarkers out of .i files. The fix is to split the C++ class typedef redefinition path from the C path, and change the C path to be a warning that normally maps to error. This causes it to properly be ignored in system headers, etc. and gives us a way to control it. Passing -Wtypedef-redefinition now turns the error into a warning. One behavior change is that we now diagnose cases where you redefine a typedef in your .c file that was defined in a header file. This seems like reasonable behavior, and the diagnostic now indicates that it can be controlled with -Wtypedef-redefinition. llvm-svn: 69391
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp27
1 files changed, 12 insertions, 15 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0fe5715578b..3a264d4449e 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -533,25 +533,22 @@ bool Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) {
// In a given non-class scope, a typedef specifier can be used to
// redefine the name of any type declared in that scope to refer
// to the type to which it already refers.
- if (getLangOptions().CPlusPlus && !isa<CXXRecordDecl>(CurContext))
- return false;
-
- // In C, redeclaration of a type is a constraint violation (6.7.2.3p1).
- // Apparently GCC, Intel, and Sun all silently ignore the redeclaration if
- // *either* declaration is in a system header. The code below implements
- // this adhoc compatibility rule. FIXME: The following code will not
- // work properly when compiling ".i" files (containing preprocessed output).
- if (PP.getDiagnostics().getSuppressSystemWarnings()) {
- SourceManager &SrcMgr = Context.getSourceManager();
- if (SrcMgr.isInSystemHeader(Old->getLocation()))
- return false;
- if (SrcMgr.isInSystemHeader(New->getLocation()))
+ if (getLangOptions().CPlusPlus) {
+ if (!isa<CXXRecordDecl>(CurContext))
return false;
+ Diag(New->getLocation(), diag::err_redefinition)
+ << New->getDeclName();
+ Diag(Old->getLocation(), diag::note_previous_definition);
+ return true;
}
- Diag(New->getLocation(), diag::err_redefinition) << New->getDeclName();
+ // If we have a redefinition of a typedef in C, emit a warning. This warning
+ // is normally mapped to an error, but can be controlled with
+ // -Wtypedef-redefinition.
+ Diag(New->getLocation(), diag::warn_redefinition_of_typedef)
+ << New->getDeclName();
Diag(Old->getLocation(), diag::note_previous_definition);
- return true;
+ return false;
}
/// DeclhasAttr - returns true if decl Declaration already has the target
OpenPOWER on IntegriCloud