Hi rafael, rnk,

Methods are thiscall by default in the MS ABI, and also in MinGW targetting GCC 
4.7 or later.

This changes the diagnostic from the technically correct but hard to understand:

  virtual function 'foo' has different calling convention attributes ('void 
()') than the function it overrides (which has calling convention 'void () 
__attribute__((thiscall))')

to the more intuitive and also correct:

  'static' member function 'foo' overrides a virtual function

We already have a test for this. Let's just run it in both ABI modes.

http://llvm-reviews.chandlerc.com/D2375

Files:
  lib/Sema/SemaDeclCXX.cpp
  test/SemaCXX/virtual-override.cpp

Index: lib/Sema/SemaDeclCXX.cpp
===================================================================
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -12058,6 +12058,14 @@
   if (NewCC == OldCC)
     return false;
 
+  // If the calling conventions mismatch because the new function is static,
+  // say that instead.
+  if (New->getStorageClass() == SC_Static) {
+    Diag(New->getLocation(), diag::err_static_overrides_virtual) << 
New->getDeclName();
+    Diag(Old->getLocation(), diag::note_overridden_virtual_function);
+    return true;
+  }
+
   Diag(New->getLocation(),
        diag::err_conflicting_overriding_cc_attributes)
     << New->getDeclName() << New->getType() << Old->getType();
Index: test/SemaCXX/virtual-override.cpp
===================================================================
--- test/SemaCXX/virtual-override.cpp
+++ test/SemaCXX/virtual-override.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -cxx-abi itanium -verify %s -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -cxx-abi microsoft -verify %s -std=c++11
 namespace T1 {
 
 class A {
Index: lib/Sema/SemaDeclCXX.cpp
===================================================================
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -12058,6 +12058,14 @@
   if (NewCC == OldCC)
     return false;
 
+  // If the calling conventions mismatch because the new function is static,
+  // say that instead.
+  if (New->getStorageClass() == SC_Static) {
+    Diag(New->getLocation(), diag::err_static_overrides_virtual) << New->getDeclName();
+    Diag(Old->getLocation(), diag::note_overridden_virtual_function);
+    return true;
+  }
+
   Diag(New->getLocation(),
        diag::err_conflicting_overriding_cc_attributes)
     << New->getDeclName() << New->getType() << Old->getType();
Index: test/SemaCXX/virtual-override.cpp
===================================================================
--- test/SemaCXX/virtual-override.cpp
+++ test/SemaCXX/virtual-override.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -cxx-abi itanium -verify %s -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -cxx-abi microsoft -verify %s -std=c++11
 namespace T1 {
 
 class A {
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to