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 | d97fb418dc40ff89e2676bea4fedf474f8bd7980 (patch) | |
tree | 780722da51e596506fb06dab050d1518d06c5954 /clang-tidy/readability | |
parent | 1bdba187ae4d86254f1d1d4fd95144a1b67b0104 (diff) |
[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.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@309668 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/readability')
-rw-r--r-- | clang-tidy/readability/RedundantMemberInitCheck.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/clang-tidy/readability/RedundantMemberInitCheck.cpp b/clang-tidy/readability/RedundantMemberInitCheck.cpp index 6d365005..8409f9f4 100644 --- a/clang-tidy/readability/RedundantMemberInitCheck.cpp +++ b/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(), |