summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIdriss Riouak <riouakidriss@hotmail.it>2018-07-17 14:35:15 +0000
committerIdriss Riouak <riouakidriss@hotmail.it>2018-07-17 14:35:15 +0000
commitb33ccb9a1b0917123f4a934a7875ad788d9295d0 (patch)
treea0c786e23fd2fc82b64638deff1ce21d6f369b1d
parent0068d003220d97dea101f39d705ec523217aceca (diff)
[clang-tidy: modernize] Fix modernize-use-equals-default with {} brackets list initialization: patch
Summary: Hello, i would like to suggest a fix for one of the checks in clang-tidy. The bug was reported in https://bugs.llvm.org/show_bug.cgi?id=38039 where you can find more information. ``` struct UOB{ UOB(const UOB &Other):j{Other.j}{} int j; }; ``` In this case the check modernize-use-equals-default does not detect copy constructors that can be defaulted; that should be: ``` struct UOB{ UOB(const UOB &Other) = default; int j; }; ``` Reviewers: aaron.ballman, hokein, alexfh Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D49356 git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@337286 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--clang-tidy/modernize/UseEqualsDefaultCheck.cpp1
-rw-r--r--test/clang-tidy/modernize-use-equals-default-copy.cpp8
2 files changed, 9 insertions, 0 deletions
diff --git a/clang-tidy/modernize/UseEqualsDefaultCheck.cpp b/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
index da716243..88f4485c 100644
--- a/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
+++ b/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
@@ -97,6 +97,7 @@ static bool isCopyConstructorAndCanBeDefaulted(ASTContext *Context,
isMemberInitializer(), forField(equalsNode(Field)),
withInitializer(anyOf(
AccessToFieldInParam,
+ initListExpr(has(AccessToFieldInParam)),
cxxConstructExpr(allOf(
hasDeclaration(cxxConstructorDecl(isCopyConstructor())),
argumentCountIs(1),
diff --git a/test/clang-tidy/modernize-use-equals-default-copy.cpp b/test/clang-tidy/modernize-use-equals-default-copy.cpp
index 26f35af3..39a864d6 100644
--- a/test/clang-tidy/modernize-use-equals-default-copy.cpp
+++ b/test/clang-tidy/modernize-use-equals-default-copy.cpp
@@ -497,3 +497,11 @@ STRUCT_WITH_COPY_CONSTRUCT(unsigned char, Hex8CopyConstruct)
STRUCT_WITH_COPY_ASSIGN(unsigned char, Hex8CopyAssign)
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use '= default' to define a trivial copy-assignment operator
// CHECK-MESSAGES: :[[@LINE-9]]:40: note:
+
+// Use of braces
+struct UOB{
+ UOB(const UOB &Other):j{Other.j}{}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default' to define a trivial copy constructor [modernize-use-equals-default]
+ // CHECK-FIXES: UOB(const UOB &Other)= default;
+ int j;
+};