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 | |
| 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')
| -rw-r--r-- | clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp | 21 | ||||
| -rw-r--r-- | clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp | 5 |
2 files changed, 14 insertions, 12 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) diff --git a/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp index 6d3650059d4..8409f9f40d2 100644 --- a/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp @@ -39,7 +39,8 @@ void RedundantMemberInitCheck::registerMatchers(MatchFinder *Finder) { forEachConstructorInitializer( cxxCtorInitializer(isWritten(), withInitializer(ignoringImplicit(Construct)), - unless(forField(hasType(isConstQualified())))) + unless(forField(hasType(isConstQualified()))), + unless(forField(hasParent(recordDecl(isUnion()))))) .bind("init"))), this); } @@ -52,7 +53,7 @@ void RedundantMemberInitCheck::check(const MatchFinder::MatchResult &Result) { Construct->getArg(0)->isDefaultArgument()) { if (Init->isAnyMemberInitializer()) { diag(Init->getSourceLocation(), "initializer for member %0 is redundant") - << Init->getMember() + << Init->getAnyMember() << FixItHint::CreateRemoval(Init->getSourceRange()); } else { diag(Init->getSourceLocation(), |

