diff options
| author | Malcolm Parsons <malcolm.parsons@gmail.com> | 2017-08-01 09:54:05 +0000 |
|---|---|---|
| committer | Malcolm Parsons <malcolm.parsons@gmail.com> | 2017-08-01 09:54:05 +0000 |
| commit | 2f968433960782f9397cd6c42aea45763c8fa64a (patch) | |
| tree | 5bf3e93b4139a9d0c322133ab7c95dc8938ea1d4 /clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp | |
| parent | 31d08b6e51f25e97cc9de9e8f1c26773c33eee1c (diff) | |
| download | bcm5719-llvm-2f968433960782f9397cd6c42aea45763c8fa64a.tar.gz bcm5719-llvm-2f968433960782f9397cd6c42aea45763c8fa64a.zip | |
[clang-tidy] Handle anonymous structs/unions in member init checks.
Use getAnyMember() instead of getMember() to avoid crash on anonymous
structs/unions.
Don't warn about initializing members of an anonymous union.
Fixes PR32966.
Reviewed by alexfh.
llvm-svn: 309668
Diffstat (limited to 'clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp')
| -rw-r--r-- | clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp index 67a2c3d5d52..b07f730380e 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp @@ -166,21 +166,22 @@ void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) { cxxConstructorDecl( isDefaultConstructor(), unless(isInstantiated()), forEachConstructorInitializer( - allOf(forField(unless(anyOf(isBitField(), - hasInClassInitializer(anything())))), - cxxCtorInitializer(isWritten(), - withInitializer(ignoringImplicit(Init))) - .bind("default")))), + cxxCtorInitializer( + forField(unless(anyOf(isBitField(), + hasInClassInitializer(anything()), + hasParent(recordDecl(isUnion()))))), + isWritten(), withInitializer(ignoringImplicit(Init))) + .bind("default"))), this); Finder->addMatcher( cxxConstructorDecl( unless(ast_matchers::isTemplateInstantiation()), forEachConstructorInitializer( - allOf(forField(hasInClassInitializer(anything())), - cxxCtorInitializer(isWritten(), - withInitializer(ignoringImplicit(Init))) - .bind("existing")))), + cxxCtorInitializer(forField(hasInClassInitializer(anything())), + isWritten(), + withInitializer(ignoringImplicit(Init))) + .bind("existing"))), this); } @@ -197,7 +198,7 @@ void UseDefaultMemberInitCheck::check(const MatchFinder::MatchResult &Result) { void UseDefaultMemberInitCheck::checkDefaultInit( const MatchFinder::MatchResult &Result, const CXXCtorInitializer *Init) { - const FieldDecl *Field = Init->getMember(); + const FieldDecl *Field = Init->getAnyMember(); SourceLocation StartLoc = Field->getLocStart(); if (StartLoc.isMacroID() && IgnoreMacros) |

