Skip to content

Commit a507a5e

Browse files
committed
do not emit -Wunused-macros warnings in -frewrite-includes mode (PR15614)
-frewrite-includes calls PP.SetMacroExpansionOnlyInDirectives() to avoid macro expansions that are useless in that mode, but this can lead to -Wunused-macros false positives. As -frewrite-includes does not emit normal warnings, block -Wunused-macros too. Differential Revision: https://reviews.llvm.org/D65371 llvm-svn: 372026
1 parent 413647d commit a507a5e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

clang/lib/Lex/PPDirectives.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2782,7 +2782,8 @@ void Preprocessor::HandleDefineDirective(
27822782
// If we need warning for not using the macro, add its location in the
27832783
// warn-because-unused-macro set. If it gets used it will be removed from set.
27842784
if (getSourceManager().isInMainFile(MI->getDefinitionLoc()) &&
2785-
!Diags->isIgnored(diag::pp_macro_not_used, MI->getDefinitionLoc())) {
2785+
!Diags->isIgnored(diag::pp_macro_not_used, MI->getDefinitionLoc()) &&
2786+
!MacroExpansionInDirectivesOverride) {
27862787
MI->setIsWarnIfUnused(true);
27872788
WarnUnusedMacroLocs.insert(MI->getDefinitionLoc());
27882789
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: %clang_cc1 -verify -Wall -Wextra -E -frewrite-includes %s
1+
// RUN: %clang_cc1 -verify -Wall -Wextra -Wunused-macros -E -frewrite-includes %s
22
// expected-no-diagnostics
33

44
#pragma GCC visibility push (default)
5+
6+
#define USED_MACRO 1
7+
int test() { return USED_MACRO; }

0 commit comments

Comments
 (0)