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

Alex Fusco via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 14 17:41:11 PDT 2019


alexfusco created this revision.
alexfusco added a project: clang.
Herald added a subscriber: cfe-commits.

This fixes the error compiling _com_ptr_t described in https://bugs.llvm.org/show_bug.cgi?id=42842

      

In MSVCCompat mode, clang already attempts to downgrade these mismatches to a warning, but because C++17 considers the specifiers part of the type, the check in MergeFunctionDecl needs to ignore these specifiers for purpose of comparison.


Repository:
  rC Clang

https://reviews.llvm.org/D67590

Files:
  lib/Sema/SemaDecl.cpp
  test/SemaCXX/ms-ignore-mismatched-except-specifier.cpp


Index: test/SemaCXX/ms-ignore-mismatched-except-specifier.cpp
===================================================================
--- /dev/null
+++ test/SemaCXX/ms-ignore-mismatched-except-specifier.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -std=c++1z -fms-extensions -fms-compatibility
+
+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: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ 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.220238.patch
Type: text/x-patch
Size: 1511 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190915/7f068de3/attachment.bin>


More information about the cfe-commits mailing list