[PATCH] D67590: Properly ignore mismatched exception specifiers in MSVC Compat mode.

Reid Kleckner via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 16 12:54:16 PDT 2019


rnk updated this revision to Diff 220376.
rnk added a comment.

- move test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67590

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/ms-exception-spec.cpp


Index: clang/test/SemaCXX/ms-exception-spec.cpp
===================================================================
--- clang/test/SemaCXX/ms-exception-spec.cpp
+++ clang/test/SemaCXX/ms-exception-spec.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-compatibility -fexceptions -fcxx-exceptions
+// RUN: %clang_cc1 -std=c++11 %s -fsyntax-only -verify -fms-compatibility -fexceptions -fcxx-exceptions
+// RUN: %clang_cc1 -std=c++17 %s -fsyntax-only -verify -fms-compatibility -fexceptions -fcxx-exceptions
 
 void f() throw(...) { }
 
@@ -7,3 +8,11 @@
 void fn() throw(S); // expected-warning {{incomplete type}} expected-note{{previous declaration}}
 void fn() throw();  // expected-warning {{does not match previous declaration}}
 }
+
+template <typename T> struct FooPtr {
+  template <typename U> FooPtr(U *p) : m_pT(nullptr) {}
+  template <> FooPtr(T *pInterface) throw() : m_pT(pInterface) {}  // expected-warning {{exception specification in declaration does not match previous declaration}}
+  T *m_pT;
+};
+struct Bar {};
+template struct FooPtr<Bar>;
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -3562,7 +3562,14 @@
       }
     }
 
-    if (OldQTypeForComparison == NewQType)
+    if (OldQTypeForComparison == NewQType ||
+        // In Microsoft compatibility mode, the intent is to only warn on
+        // mismatched exception specifiers.  By this point, that warning has
+        // already been issued, so we should treat mismatches only in exception
+        // specifier as equivalent.
+        (getLangOpts().MSVCCompat &&
+         Context.hasSameFunctionTypeIgnoringExceptionSpec(OldQTypeForComparison,
+                                                          NewQType)))
       return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
 
     // If the types are imprecise (due to dependent constructs in friends or


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67590.220376.patch
Type: text/x-patch
Size: 1997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190916/89888545/attachment.bin>


More information about the cfe-commits mailing list