mirror of https://github.com/microsoft/clang.git
Sema: do not warn about unused const vars if main file is a header
If we pass a header to libclang, e.g. because it's open in an editor in an IDE, warnings about unused const vars are not useful: other files that include the header might use those constants. So when -x *-header is passed as command-line option, suppress this warning. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285386 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
12d561376a
commit
2a5ffb8501
|
@ -865,8 +865,11 @@ void Sema::ActOnEndOfTranslationUnit() {
|
||||||
Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
|
Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
|
||||||
<< /*variable*/1 << DiagD->getDeclName();
|
<< /*variable*/1 << DiagD->getDeclName();
|
||||||
} else if (DiagD->getType().isConstQualified()) {
|
} else if (DiagD->getType().isConstQualified()) {
|
||||||
Diag(DiagD->getLocation(), diag::warn_unused_const_variable)
|
const SourceManager &SM = SourceMgr;
|
||||||
<< DiagD->getDeclName();
|
if (SM.getMainFileID() != SM.getFileID(DiagD->getLocation()) ||
|
||||||
|
!PP.getLangOpts().IsHeaderFile)
|
||||||
|
Diag(DiagD->getLocation(), diag::warn_unused_const_variable)
|
||||||
|
<< DiagD->getDeclName();
|
||||||
} else {
|
} else {
|
||||||
Diag(DiagD->getLocation(), diag::warn_unused_variable)
|
Diag(DiagD->getLocation(), diag::warn_unused_variable)
|
||||||
<< DiagD->getDeclName();
|
<< DiagD->getDeclName();
|
||||||
|
|
|
@ -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 };
|
Loading…
Reference in New Issue