[PATCH] D16376: clang-tidy check: User-defined copy without assignment

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 21 07:03:59 PST 2016


aaron.ballman added subscribers: dblaikie, rsmith.

================
Comment at: clang-tidy/misc/UserDefinedCopyWithoutAssignmentCheck.cpp:51
@@ +50,3 @@
+
+  Diag << FixItHint::CreateInsertion(CCtorEnd, Insertion.str());
+}
----------------
alexfh wrote:
> aaron.ballman wrote:
> > We probably do not want to generate this fixit unless we are compiling for at least C++11. We should have a test for C++98.
> Just insert this at the start of `registerMatchers`:
> 
>   if (!getLangOpts().CPlusPlus11)
>     return;
I think the check is still useful in C++98 mode assuming older versions of MSVC (before they started supporting C++11) have the same behavior. The fixit isn't useful, but warning the user about the problem is.

================
Comment at: docs/clang-tidy/checks/misc-user-defined-copy-without-assignment.rst:6
@@ +5,3 @@
+
+MSVC 2015 will generate an assignment operator even if the user defines a copy constructor.
+This check finds classes with a user-defined (including deleted)
----------------
alexfh wrote:
> Is this problem only relevant to MSVC 2015? Is MSVC's behavior standard-compliant in this case?
MSVC's behavior is standards compliant, but is deprecated behavior. [class.copy]p18:

"If the class definition does not explicitly declare a copy assignment operator, one is declared implicitly. If
the class definition declares a move constructor or move assignment operator, the implicitly declared copy
assignment operator is defined as deleted; otherwise, it is defined as defaulted (8.4). The latter case is
deprecated if the class has a user-declared copy constructor or a user-declared destructor."

Now that I think about it more, I thought @dblaikie or @rsmith made a check for this once under -Wdeprecated. It looks like Richard did in r183884.


Repository:
  rL LLVM

http://reviews.llvm.org/D16376





More information about the cfe-commits mailing list