Index: clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.h =================================================================== --- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.h +++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.h @@ -36,6 +36,7 @@ const CXXCtorInitializer *Init); const bool UseAssignment; + const bool IgnoreMacros; }; } // namespace modernize Index: clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp @@ -139,11 +139,13 @@ UseDefaultMemberInitCheck::UseDefaultMemberInitCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), - UseAssignment(Options.get("UseAssignment", 0) != 0) {} + UseAssignment(Options.get("UseAssignment", 0) != 0), + IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", 1) != 0) {} void UseDefaultMemberInitCheck::storeOptions( ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "UseAssignment", UseAssignment); + Options.store(Opts, "IgnoreMacros", IgnoreMacros); } void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) { @@ -197,6 +199,10 @@ const MatchFinder::MatchResult &Result, const CXXCtorInitializer *Init) { const FieldDecl *Field = Init->getMember(); + SourceLocation StartLoc = Field->getLocStart(); + if (StartLoc.isMacroID() && IgnoreMacros) + return; + SourceLocation FieldEnd = Lexer::getLocForEndOfToken(Field->getSourceRange().getEnd(), 0, *Result.SourceManager, getLangOpts()); Index: clang-tools-extra/trunk/clang-tidy/modernize/UseUsingCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/modernize/UseUsingCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/modernize/UseUsingCheck.cpp @@ -19,7 +19,7 @@ UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), - IgnoreMacros(Options.get("IgnoreMacros", true)) {} + IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {} void UseUsingCheck::registerMatchers(MatchFinder *Finder) { if (!getLangOpts().CPlusPlus11) Index: clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-default-member-init.rst =================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-default-member-init.rst +++ clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-default-member-init.rst @@ -47,3 +47,8 @@ int i = 5; double j = 10.0; }; + +.. option:: IgnoreMacros + + If this option is set to non-zero (default is `1`), the check will not warn + about members declared inside macros. Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init-macros.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init-macros.cpp +++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init-macros.cpp @@ -0,0 +1,18 @@ +// RUN: %check_clang_tidy %s modernize-use-default-member-init %t -- \ +// RUN: -config="{CheckOptions: [{key: modernize-use-default-member-init.IgnoreMacros, value: 0}]}" \ +// RUN: -- -std=c++11 + +#define MACRO() \ + struct S { \ + void *P; \ + S() : P(nullptr) {} \ + }; + +MACRO(); +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use default member initializer for 'P' + +struct S2 { + void *P; + // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use default member initializer for 'P' + S2() : P(nullptr) {} +}; Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp +++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp @@ -380,3 +380,12 @@ NegativeTemplateExisting ntei(0); NegativeTemplateExisting nted(0); + +// This resulted in a warning by default. +#define MACRO() \ + struct MacroS { \ + void *P; \ + MacroS() : P(nullptr) {} \ + }; + +MACRO();