r197055 - Better diagnostic for static override when methods are thiscall by default
Hans Wennborg
hans at hanshq.net
Wed Dec 11 09:42:11 PST 2013
Author: hans
Date: Wed Dec 11 11:42:11 2013
New Revision: 197055
URL: http://llvm.org/viewvc/llvm-project?rev=197055&view=rev
Log:
Better diagnostic for static override when methods are thiscall by default
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.
Differential Revision: http://llvm-reviews.chandlerc.com/D2375
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/virtual-override.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=197055&r1=197054&r2=197055&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Dec 11 11:42:11 2013
@@ -12058,6 +12058,13 @@ bool Sema::CheckOverridingFunctionAttrib
if (NewCC == OldCC)
return false;
+ // If the calling conventions mismatch because the new function is static,
+ // suppress the calling convention mismatch error; the error about static
+ // function override (err_static_overrides_virtual from
+ // Sema::CheckFunctionDeclaration) is more clear.
+ if (New->getStorageClass() == SC_Static)
+ return false;
+
Diag(New->getLocation(),
diag::err_conflicting_overriding_cc_attributes)
<< New->getDeclName() << New->getType() << Old->getType();
Modified: cfe/trunk/test/SemaCXX/virtual-override.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/virtual-override.cpp?rev=197055&r1=197054&r2=197055&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/virtual-override.cpp (original)
+++ cfe/trunk/test/SemaCXX/virtual-override.cpp Wed Dec 11 11:42:11 2013
@@ -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 {
More information about the cfe-commits
mailing list