[PATCH] Fix PR15558
Matt Beaumont-Gay
matthewbg at google.com
Mon Apr 8 15:58:10 PDT 2013
Addressed review comments.
Hi rsmith, nlewycky,
http://llvm-reviews.chandlerc.com/D597
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D597?vs=1445&id=1553#toc
Files:
lib/Sema/Sema.cpp
test/SemaCXX/Inputs/warn-unused-variables.h
test/SemaCXX/warn-unused-variables-error.cpp
test/SemaCXX/warn-unused-variables.cpp
Index: lib/Sema/Sema.cpp
===================================================================
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -751,9 +751,13 @@
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();
}
}
}
Index: test/SemaCXX/Inputs/warn-unused-variables.h
===================================================================
--- /dev/null
+++ test/SemaCXX/Inputs/warn-unused-variables.h
@@ -0,0 +1,11 @@
+// Verify that we don't warn about variables of internal-linkage type in
+// headers, as the use may be in another TU.
+namespace PR15558 {
+namespace {
+class A {};
+}
+
+class B {
+ static A a;
+};
+}
Index: test/SemaCXX/warn-unused-variables-error.cpp
===================================================================
--- /dev/null
+++ test/SemaCXX/warn-unused-variables-error.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -verify %s
+
+namespace PR6948 {
+ template<typename T> class X; // expected-note{{template is declared here}}
+
+ void f() {
+ X<char> str (read_from_file()); // expected-error{{use of undeclared identifier 'read_from_file'}} \
+ expected-error{{implicit instantiation of undefined template 'PR6948::X<char>'}}
+ }
+}
Index: test/SemaCXX/warn-unused-variables.cpp
===================================================================
--- test/SemaCXX/warn-unused-variables.cpp
+++ test/SemaCXX/warn-unused-variables.cpp
@@ -41,15 +41,6 @@
(void)i;
}
-namespace PR6948 {
- template<typename T> class X; // expected-note{{template is declared here}}
-
- void f() {
- X<char> str (read_from_file()); // expected-error{{use of undeclared identifier 'read_from_file'}} \
- expected-error{{implicit instantiation of undefined template 'PR6948::X<char>'}}
- }
-}
-
void unused_local_static() {
static int x = 0;
static int y = 0; // expected-warning{{unused variable 'y'}}
@@ -135,3 +126,5 @@
S2 s((S1()));
}
}
+
+#include "Inputs/warn-unused-variables.h"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D597.2.patch
Type: text/x-patch
Size: 2679 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130408/97613f67/attachment.bin>
More information about the cfe-commits
mailing list