summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/Sema.cpp7
-rw-r--r--clang/test/Sema/no-warn-unused-const-variables.c4
2 files changed, 9 insertions, 2 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 2a3be84263c..c2622ecab4b 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -865,8 +865,11 @@ void Sema::ActOnEndOfTranslationUnit() {
Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
<< /*variable*/1 << DiagD->getDeclName();
} else if (DiagD->getType().isConstQualified()) {
- Diag(DiagD->getLocation(), diag::warn_unused_const_variable)
- << DiagD->getDeclName();
+ const SourceManager &SM = SourceMgr;
+ if (SM.getMainFileID() != SM.getFileID(DiagD->getLocation()) ||
+ !PP.getLangOpts().IsHeaderFile)
+ Diag(DiagD->getLocation(), diag::warn_unused_const_variable)
+ << DiagD->getDeclName();
} else {
Diag(DiagD->getLocation(), diag::warn_unused_variable)
<< DiagD->getDeclName();
diff --git a/clang/test/Sema/no-warn-unused-const-variables.c b/clang/test/Sema/no-warn-unused-const-variables.c
new file mode 100644
index 00000000000..73cfd8ea71b
--- /dev/null
+++ b/clang/test/Sema/no-warn-unused-const-variables.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-const-variable -x c-header -ffreestanding -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-const-variable -x c++-header -ffreestanding -verify %s
+// expected-no-diagnostics
+static const int unused[] = { 2, 3, 5, 7, 11, 13 };
OpenPOWER on IntegriCloud