[PATCH] D133354: [Clang]: Diagnose deprecated copy operations also in MSVC compatibility mode

Hans Wennborg via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 14 10:48:44 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG49e7ef2c09fa: [Clang]: Diagnose deprecated copy operations also in MSVC compatibility mode (authored by ningvin, committed by hans).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133354/new/

https://reviews.llvm.org/D133354

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/deprecated-copy-with-dtor.cpp
  clang/test/SemaCXX/deprecated-copy-with-user-provided-copy.cpp
  clang/test/SemaCXX/deprecated-copy-with-user-provided-dtor.cpp
  clang/test/SemaCXX/deprecated-copy.cpp
  clang/test/SemaCXX/deprecated.cpp


Index: clang/test/SemaCXX/deprecated.cpp
===================================================================
--- clang/test/SemaCXX/deprecated.cpp
+++ clang/test/SemaCXX/deprecated.cpp
@@ -1,10 +1,16 @@
 // RUN: %clang_cc1 -std=c++98 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu
+// RUN: %clang_cc1 -std=c++98 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu -fms-compatibility
 // RUN: %clang_cc1 -std=c++11 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu
+// RUN: %clang_cc1 -std=c++11 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu -fms-compatibility
 // RUN: %clang_cc1 -std=c++14 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu
+// RUN: %clang_cc1 -std=c++14 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu -fms-compatibility
 // RUN: %clang_cc1 -std=c++17 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu
+// RUN: %clang_cc1 -std=c++17 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu -fms-compatibility
 // RUN: %clang_cc1 -std=c++2a %s -Wno-parentheses -Wdeprecated -verify=expected,cxx20 -triple x86_64-linux-gnu
+// RUN: %clang_cc1 -std=c++2a %s -Wno-parentheses -Wdeprecated -verify=expected,cxx20 -triple x86_64-linux-gnu -fms-compatibility
 
 // RUN: %clang_cc1 -std=c++14 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu -Wno-deprecated-register -DNO_DEPRECATED_FLAGS
+// RUN: %clang_cc1 -std=c++14 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu -Wno-deprecated-register -DNO_DEPRECATED_FLAGS -fms-compatibility
 
 #include "Inputs/register.h"
 
Index: clang/test/SemaCXX/deprecated-copy.cpp
===================================================================
--- clang/test/SemaCXX/deprecated-copy.cpp
+++ clang/test/SemaCXX/deprecated-copy.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify -fms-compatibility
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy -verify
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy -verify -fms-compatibility
 
 struct A {
     A& operator=(const A&) = default; // expected-warning {{definition of implicit copy constructor for 'A' is deprecated because it has a user-declared copy assignment operator}}
Index: clang/test/SemaCXX/deprecated-copy-with-user-provided-dtor.cpp
===================================================================
--- clang/test/SemaCXX/deprecated-copy-with-user-provided-dtor.cpp
+++ clang/test/SemaCXX/deprecated-copy-with-user-provided-dtor.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify -fms-compatibility
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy-with-user-provided-dtor -verify
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy-with-user-provided-dtor -verify -fms-compatibility
 
 struct A {
   ~A(); // expected-warning {{definition of implicit copy constructor for 'A' is deprecated because it has a user-provided destructor}}
Index: clang/test/SemaCXX/deprecated-copy-with-user-provided-copy.cpp
===================================================================
--- clang/test/SemaCXX/deprecated-copy-with-user-provided-copy.cpp
+++ clang/test/SemaCXX/deprecated-copy-with-user-provided-copy.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify -fms-compatibility
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy-with-user-provided-copy -verify
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy-with-user-provided-copy -verify -fms-compatibility
 
 struct A {
   A &operator=(const A &); // expected-warning {{definition of implicit copy constructor for 'A' is deprecated because it has a user-provided copy assignment operator}}
Index: clang/test/SemaCXX/deprecated-copy-with-dtor.cpp
===================================================================
--- clang/test/SemaCXX/deprecated-copy-with-dtor.cpp
+++ clang/test/SemaCXX/deprecated-copy-with-dtor.cpp
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify -fms-compatibility
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy-dtor -verify
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy-dtor -verify -fms-compatibility
 // RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy-with-dtor -verify
+// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy-with-dtor -verify -fms-compatibility
 
 class A {
 public:
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -14429,13 +14429,10 @@
   CXXRecordDecl *RD = CopyOp->getParent();
   CXXMethodDecl *UserDeclaredOperation = nullptr;
 
-  // In Microsoft mode, assignment operations don't affect constructors and
-  // vice versa.
   if (RD->hasUserDeclaredDestructor()) {
     UserDeclaredOperation = RD->getDestructor();
   } else if (!isa<CXXConstructorDecl>(CopyOp) &&
-             RD->hasUserDeclaredCopyConstructor() &&
-             !S.getLangOpts().MSVCCompat) {
+             RD->hasUserDeclaredCopyConstructor()) {
     // Find any user-declared copy constructor.
     for (auto *I : RD->ctors()) {
       if (I->isCopyConstructor()) {
@@ -14445,8 +14442,7 @@
     }
     assert(UserDeclaredOperation);
   } else if (isa<CXXConstructorDecl>(CopyOp) &&
-             RD->hasUserDeclaredCopyAssignment() &&
-             !S.getLangOpts().MSVCCompat) {
+             RD->hasUserDeclaredCopyAssignment()) {
     // Find any user-declared move assignment operator.
     for (auto *I : RD->methods()) {
       if (I->isCopyAssignmentOperator()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133354.460153.patch
Type: text/x-patch
Size: 5973 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220914/e498f77d/attachment.bin>


More information about the cfe-commits mailing list