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


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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to