diff options
author | Matt Beaumont-Gay <matthewbg@google.com> | 2013-04-10 00:47:10 +0000 |
---|---|---|
committer | Matt Beaumont-Gay <matthewbg@google.com> | 2013-04-10 00:47:10 +0000 |
commit | e1368a107a3ec58b121d369468d8d047c3201395 (patch) | |
tree | 47acbffa7ae72b43c294c69480d19b324ad7134a /clang/lib/Sema/Sema.cpp | |
parent | b0640dc2b664ba74496ae83740cf66b8fbebaa32 (diff) | |
download | bcm5719-llvm-e1368a107a3ec58b121d369468d8d047c3201395.tar.gz bcm5719-llvm-e1368a107a3ec58b121d369468d8d047c3201395.zip |
Suppress -Wunused-variable for variables declared in headers, which may in
fact be defined and used in another TU.
Reshuffle some test cases because we suppress -Wunused-variable after we've
emitted an error.
This fixes PR15558.
llvm-svn: 179138
Diffstat (limited to 'clang/lib/Sema/Sema.cpp')
-rw-r--r-- | clang/lib/Sema/Sema.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 6bab9e80cbf..e271f78ed0c 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -751,9 +751,13 @@ void Sema::ActOnEndOfTranslationUnit() { if (DiagD->isReferenced()) { Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl) << /*variable*/1 << DiagD->getDeclName(); - } else { + } else if (getSourceManager().isFromMainFile(DiagD->getLocation())) { + // If the declaration is in a header which is included into multiple + // TUs, it will declare one variable per TU, and one of the other + // variables may be used. So, only warn if the declaration is in the + // main file. Diag(DiagD->getLocation(), diag::warn_unused_variable) - << DiagD->getDeclName(); + << DiagD->getDeclName(); } } } |