summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
diff options
context:
space:
mode:
authorMalcolm Parsons <malcolm.parsons@gmail.com>2017-08-01 09:54:05 +0000
committerMalcolm Parsons <malcolm.parsons@gmail.com>2017-08-01 09:54:05 +0000
commit2f968433960782f9397cd6c42aea45763c8fa64a (patch)
tree5bf3e93b4139a9d0c322133ab7c95dc8938ea1d4 /clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
parent31d08b6e51f25e97cc9de9e8f1c26773c33eee1c (diff)
downloadbcm5719-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/readability/RedundantMemberInitCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp5
1 files changed, 3 insertions, 2 deletions
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(),
OpenPOWER on IntegriCloud