r192244 - -Wmicrosoft: Don't warn on non-inline pure virtual method definitions

Reid Kleckner reid at kleckner.net
Tue Oct 8 15:45:29 PDT 2013


Author: rnk
Date: Tue Oct  8 17:45:29 2013
New Revision: 192244

URL: http://llvm.org/viewvc/llvm-project?rev=192244&view=rev
Log:
-Wmicrosoft: Don't warn on non-inline pure virtual method definitions

MSVC and clang with -fms-extensions allow pure virtual methods to be
defined inline after the "= 0" tokens.  Clang warns on these because it
is not standard, but incorrectly warns on out-of-line definitions, which
are standard.

With this change, clang will only warn on inline definitions of pure
virtual methods.

Fixes some self-host warnings on out-of-line definitions of pure virtual
destructors.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Parser/MicrosoftExtensions.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=192244&r1=192243&r2=192244&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Oct  8 17:45:29 2013
@@ -9633,7 +9633,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl
 
     // MSVC permits the use of pure specifier (=0) on function definition,
     // defined at class scope, warn about this non standard construct.
-    if (getLangOpts().MicrosoftExt && FD->isPure())
+    if (getLangOpts().MicrosoftExt && FD->isPure() && FD->isCanonicalDecl())
       Diag(FD->getLocation(), diag::warn_pure_function_definition);
 
     if (!FD->isInvalidDecl()) {

Modified: cfe/trunk/test/Parser/MicrosoftExtensions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/MicrosoftExtensions.cpp?rev=192244&r1=192243&r2=192244&view=diff
==============================================================================
--- cfe/trunk/test/Parser/MicrosoftExtensions.cpp (original)
+++ cfe/trunk/test/Parser/MicrosoftExtensions.cpp Tue Oct  8 17:45:29 2013
@@ -331,6 +331,15 @@ class inline_definition_pure_spec {
    virtual int f2() = 0;
 };
 
+struct pure_virtual_dtor {
+  virtual ~pure_virtual_dtor() = 0;
+};
+pure_virtual_dtor::~pure_virtual_dtor() { }
+
+struct pure_virtual_dtor_inline {
+  virtual ~pure_virtual_dtor_inline() = 0 { }// expected-warning {{function definition with pure-specifier is a Microsoft extension}}
+};
+
 
 int main () {
   // Necessary to force instantiation in -fdelayed-template-parsing mode.





More information about the cfe-commits mailing list