From 163ada8a0f56a9928feaaaf11a4eb7d41f65a0e2 Mon Sep 17 00:00:00 2001 From: Abramo Bagnara Date: Sun, 1 Jan 2012 22:01:04 +0000 Subject: [PATCH] Added -Wdisabled-macro-expansion warning. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147418 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticLexKinds.td | 3 +++ lib/Lex/Preprocessor.cpp | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/clang/Basic/DiagnosticLexKinds.td b/include/clang/Basic/DiagnosticLexKinds.td index 41c67fb1f2..f4d867d4fe 100644 --- a/include/clang/Basic/DiagnosticLexKinds.td +++ b/include/clang/Basic/DiagnosticLexKinds.td @@ -167,6 +167,9 @@ def pp_out_of_date_dependency : Warning< def pp_undef_builtin_macro : Warning<"undefining builtin macro">; def pp_redef_builtin_macro : Warning<"redefining builtin macro">, InGroup>; +def pp_disabled_macro_expansion : Warning< + "disabled expansion of recursive macro">, DefaultIgnore, + InGroup>; def pp_macro_not_used : Warning<"macro is not used">, DefaultIgnore, InGroup>; def warn_pp_undef_identifier : Warning< diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index dea7efc765..90b6798466 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -509,8 +509,10 @@ void Preprocessor::HandleIdentifier(Token &Identifier) { // If this is a macro to be expanded, do it. if (MacroInfo *MI = getMacroInfo(&II)) { - if (!DisableMacroExpansion && !Identifier.isExpandDisabled()) { - if (MI->isEnabled()) { + if (!DisableMacroExpansion) { + if (Identifier.isExpandDisabled()) { + Diag(Identifier, diag::pp_disabled_macro_expansion); + } else if (MI->isEnabled()) { if (!HandleMacroExpandedIdentifier(Identifier, MI)) return; } else { @@ -518,6 +520,7 @@ void Preprocessor::HandleIdentifier(Token &Identifier) { // expanded, even if it's in a context where it could be expanded in the // future. Identifier.setFlag(Token::DisableExpand); + Diag(Identifier, diag::pp_disabled_macro_expansion); } } } -- 2.50.1