[PATCH] D75901: [clang-tidy] misc-unconventional-assign-operator suggest to use rvalue references in C++03 mode
Alex Cameron via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 10 03:46:44 PDT 2020
tetsuo-cpp created this revision.
tetsuo-cpp added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.
tetsuo-cpp added reviewers: njames93, MaskRay.
Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=27702
I wasn't sure how this type of thing is usually tested. So any advice would be appreciated.
`check-llvm`, `check-clang` and `check-clang-tools` are clean for me.
**C++98**
tetsuo at garland-c-16-sgp1-01:~/dev/llvm-project/test$ cat compile_commands.json
[
{
"directory": "/home/tetsuo/dev/llvm-project/test",
"command": "/usr/bin/c++ -std=gnu++98 -o CMakeFiles/test.dir/test.cpp.o -c /home/tetsuo/dev/llvm-project/test/test.cpp",
"file": "/home/tetsuo/dev/llvm-project/test/test.cpp"
}
]
tetsuo at garland-c-16-sgp1-01:~/dev/llvm-project/test$ ../build/bin/clang-tidy --checks=misc-unconventional-assign-operator test.cpp
3053 warnings generated.
/home/tetsuo/dev/llvm-project/test/test.cpp:7:3: warning: operator=() should take 'Foo const&' or 'Foo' [misc-unconventional-assign-operator]
Foo &operator=(Foo &Other) {
^
Suppressed 3052 warnings (3052 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
**C++17**
tetsuo at garland-c-16-sgp1-01:~/dev/llvm-project/test$ cat compile_commands.json
[
{
"directory": "/home/tetsuo/dev/llvm-project/test",
"command": "/usr/bin/c++ -std=gnu++17 -o CMakeFiles/test.dir/test.cpp.o -c /home/tetsuo/dev/llvm-project/test/test.cpp",
"file": "/home/tetsuo/dev/llvm-project/test/test.cpp"
}
]
tetsuo at garland-c-16-sgp1-01:~/dev/llvm-project/test$ ../build/bin/clang-tidy --checks=misc-unconventional-assign-operator test.cpp
5377 warnings generated.
/home/tetsuo/dev/llvm-project/test/test.cpp:7:3: warning: operator=() should take 'Foo const&', 'Foo&&' or 'Foo' [misc-unconventional-assign-operator]
Foo &operator=(Foo &Other) {
^
Suppressed 5376 warnings (5376 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D75901
Files:
clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
Index: clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
@@ -73,9 +73,14 @@
if (const auto *RetStmt = Result.Nodes.getNodeAs<ReturnStmt>("returnStmt")) {
diag(RetStmt->getBeginLoc(), "operator=() should always return '*this'");
} else {
+ const ASTContext *ASTCtx = Result.Context;
+ const LangOptions &Opts = ASTCtx->getLangOpts();
static const char *const Messages[][2] = {
{"ReturnType", "operator=() should return '%0&'"},
- {"ArgumentType", "operator=() should take '%0 const&', '%0&&' or '%0'"},
+ {"ArgumentType",
+ Opts.CPlusPlus11
+ ? "operator=() should take '%0 const&', '%0&&' or '%0'"
+ : "operator=() should take '%0 const&' or '%0'"},
{"cv", "operator=() should not be marked '%1'"}};
const auto *Method = Result.Nodes.getNodeAs<CXXMethodDecl>("method");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75901.249296.patch
Type: text/x-patch
Size: 1105 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200310/fc074346/attachment.bin>
More information about the cfe-commits
mailing list