[clang-tools-extra] r337286 - [clang-tidy: modernize] Fix modernize-use-equals-default with {} brackets list initialization: patch
Idriss Riouak via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 17 07:35:16 PDT 2018
Author: idrissrio
Date: Tue Jul 17 07:35:15 2018
New Revision: 337286
URL: http://llvm.org/viewvc/llvm-project?rev=337286&view=rev
Log:
[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
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-default-copy.cpp
Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDefaultCheck.cpp?rev=337286&r1=337285&r2=337286&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDefaultCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDefaultCheck.cpp Tue Jul 17 07:35:15 2018
@@ -97,6 +97,7 @@ static bool isCopyConstructorAndCanBeDef
isMemberInitializer(), forField(equalsNode(Field)),
withInitializer(anyOf(
AccessToFieldInParam,
+ initListExpr(has(AccessToFieldInParam)),
cxxConstructExpr(allOf(
hasDeclaration(cxxConstructorDecl(isCopyConstructor())),
argumentCountIs(1),
Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-default-copy.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-default-copy.cpp?rev=337286&r1=337285&r2=337286&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-default-copy.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-default-copy.cpp Tue Jul 17 07:35:15 2018
@@ -497,3 +497,11 @@ STRUCT_WITH_COPY_CONSTRUCT(unsigned char
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;
+};
More information about the cfe-commits
mailing list