[PATCH] Better diagnostic for static function overriding thiscall virtual method

Hans Wennborg hans at chromium.org
Tue Dec 10 15:13:06 PST 2013


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 {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2375.1.patch
Type: text/x-patch
Size: 1142 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131210/5b99abf5/attachment.bin>


More information about the cfe-commits mailing list