xbolva00 created this revision.
xbolva00 added a reviewer: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

GCC 9 added -Wdeprecated-copy (as part of -Wextra). This diagnostic is already 
implemented in Clang too, just hidden under -Wdeprecated (not on by default).
This patch adds -Wdeprecated-copy and makes it compatible with GCC 9+.
This diagnostic is heavily tested in deprecated.cpp, so I added simple tests 
just to check we warn when new flag/-Wextra is enabled.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70342

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/test/SemaCXX/deprecated-copy.cpp


Index: clang/test/SemaCXX/deprecated-copy.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/deprecated-copy.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy -verify
+// RUN: %clang_cc1 -std=c++14 %s -Wdeprecated-copy -verify
+// RUN: %clang_cc1 -std=c++17 %s -Wdeprecated-copy -verify
+// RUN: %clang_cc1 -std=c++2a %s -Wdeprecated-copy -verify
+
+// RUN: %clang_cc1 -std=c++11 %s -Wextra -verify
+// RUN: %clang_cc1 -std=c++14 %s -Wextra -verify
+// RUN: %clang_cc1 -std=c++17 %s -Wextra -verify
+// RUN: %clang_cc1 -std=c++2a %s -Wextra -verify
+
+struct A {
+  int *ptr;
+  ~A() { delete ptr; } // expected-warning {{definition of implicit copy 
constructor for 'A' is deprecated because it has a user-declared destructor}}
+};
+
+struct B {
+  B &operator=(const B &); // expected-warning {{definition of implicit copy 
constructor for 'B' is deprecated because it has a user-declared copy 
assignment operator}}
+};
+
+void foo() {
+  A a{};
+  A b = a;      // expected-note {{implicit copy constructor for 'A' first 
required here}}
+  B b1, b2(b1); // expected-note {{implicit copy constructor for 'B' first 
required here}}
+}
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -553,7 +553,7 @@
   "definition of implicit copy %select{constructor|assignment operator}1 "
   "for %0 is deprecated because it has a user-declared "
   "%select{copy %select{assignment operator|constructor}1|destructor}2">,
-  InGroup<Deprecated>, DefaultIgnore;
+  InGroup<DeprecatedCopy>, DefaultIgnore;
 def warn_cxx17_compat_exception_spec_in_signature : Warning<
   "mangled name of %0 will change in C++17 due to non-throwing exception "
   "specification in function signature">, InGroup<CXX17CompatMangling>;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===================================================================
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -128,6 +128,7 @@
 
 def DeprecatedAttributes : DiagGroup<"deprecated-attributes">;
 def DeprecatedCommaSubscript : DiagGroup<"deprecated-comma-subscript">;
+def DeprecatedCopy : DiagGroup<"deprecated-copy">;
 def DeprecatedDeclarations : DiagGroup<"deprecated-declarations">;
 def UnavailableDeclarations : DiagGroup<"unavailable-declarations">;
 def UnguardedAvailabilityNew : DiagGroup<"unguarded-availability-new">;
@@ -147,6 +148,7 @@
 // FIXME: Why is DeprecatedImplementations not in this group?
 def Deprecated : DiagGroup<"deprecated", [DeprecatedAttributes,
                                           DeprecatedCommaSubscript,
+                                          DeprecatedCopy,
                                           DeprecatedDeclarations,
                                           DeprecatedDynamicExceptionSpec,
                                           DeprecatedIncrementBool,
@@ -812,6 +814,7 @@
   ]>;
 
 def Extra : DiagGroup<"extra", [
+    DeprecatedCopy,
     MissingFieldInitializers,
     IgnoredQualifiers,
     InitializerOverrides,


Index: clang/test/SemaCXX/deprecated-copy.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/deprecated-copy.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy -verify
+// RUN: %clang_cc1 -std=c++14 %s -Wdeprecated-copy -verify
+// RUN: %clang_cc1 -std=c++17 %s -Wdeprecated-copy -verify
+// RUN: %clang_cc1 -std=c++2a %s -Wdeprecated-copy -verify
+
+// RUN: %clang_cc1 -std=c++11 %s -Wextra -verify
+// RUN: %clang_cc1 -std=c++14 %s -Wextra -verify
+// RUN: %clang_cc1 -std=c++17 %s -Wextra -verify
+// RUN: %clang_cc1 -std=c++2a %s -Wextra -verify
+
+struct A {
+  int *ptr;
+  ~A() { delete ptr; } // expected-warning {{definition of implicit copy constructor for 'A' is deprecated because it has a user-declared destructor}}
+};
+
+struct B {
+  B &operator=(const B &); // expected-warning {{definition of implicit copy constructor for 'B' is deprecated because it has a user-declared copy assignment operator}}
+};
+
+void foo() {
+  A a{};
+  A b = a;      // expected-note {{implicit copy constructor for 'A' first required here}}
+  B b1, b2(b1); // expected-note {{implicit copy constructor for 'B' first required here}}
+}
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -553,7 +553,7 @@
   "definition of implicit copy %select{constructor|assignment operator}1 "
   "for %0 is deprecated because it has a user-declared "
   "%select{copy %select{assignment operator|constructor}1|destructor}2">,
-  InGroup<Deprecated>, DefaultIgnore;
+  InGroup<DeprecatedCopy>, DefaultIgnore;
 def warn_cxx17_compat_exception_spec_in_signature : Warning<
   "mangled name of %0 will change in C++17 due to non-throwing exception "
   "specification in function signature">, InGroup<CXX17CompatMangling>;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===================================================================
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -128,6 +128,7 @@
 
 def DeprecatedAttributes : DiagGroup<"deprecated-attributes">;
 def DeprecatedCommaSubscript : DiagGroup<"deprecated-comma-subscript">;
+def DeprecatedCopy : DiagGroup<"deprecated-copy">;
 def DeprecatedDeclarations : DiagGroup<"deprecated-declarations">;
 def UnavailableDeclarations : DiagGroup<"unavailable-declarations">;
 def UnguardedAvailabilityNew : DiagGroup<"unguarded-availability-new">;
@@ -147,6 +148,7 @@
 // FIXME: Why is DeprecatedImplementations not in this group?
 def Deprecated : DiagGroup<"deprecated", [DeprecatedAttributes,
                                           DeprecatedCommaSubscript,
+                                          DeprecatedCopy,
                                           DeprecatedDeclarations,
                                           DeprecatedDynamicExceptionSpec,
                                           DeprecatedIncrementBool,
@@ -812,6 +814,7 @@
   ]>;
 
 def Extra : DiagGroup<"extra", [
+    DeprecatedCopy,
     MissingFieldInitializers,
     IgnoredQualifiers,
     InitializerOverrides,
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to