r358849 - [Sema][MSVC] Fix bogus microsoft-pure-definition warning on member function of class template

Bruno Ricci via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 21 06:12:10 PDT 2019


Author: brunoricci
Date: Sun Apr 21 06:12:10 2019
New Revision: 358849

URL: http://llvm.org/viewvc/llvm-project?rev=358849&view=rev
Log:
[Sema][MSVC] Fix bogus microsoft-pure-definition warning on member function of class template

Clang emits a warning when using a pure specifier =0 in a function definition
at class scope (a MS-specific construct), when using -fms-extensions.
However, to detect this, it was using FD->isCanonicalDecl() on function
declaration, which was also detecting out-of-class definition of member
functions of class templates. Fix this by using !FD->isOutOfLine() instead.

Fixes PR21334.

Differential Revision: https://reviews.llvm.org/D29707

Reviewed By: riccibruno

Reviewers: rnk, riccibruno

Patch By: Rudy Pons


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=358849&r1=358848&r2=358849&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Apr 21 06:12:10 2019
@@ -13244,7 +13244,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() && FD->isCanonicalDecl())
+    if (getLangOpts().MicrosoftExt && FD->isPure() && !FD->isOutOfLine())
       Diag(FD->getLocation(), diag::ext_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=358849&r1=358848&r2=358849&view=diff
==============================================================================
--- cfe/trunk/test/Parser/MicrosoftExtensions.cpp (original)
+++ cfe/trunk/test/Parser/MicrosoftExtensions.cpp Sun Apr 21 06:12:10 2019
@@ -288,6 +288,18 @@ struct pure_virtual_dtor_inline {
   virtual ~pure_virtual_dtor_inline() = 0 { }// expected-warning {{function definition with pure-specifier is a Microsoft extension}}
 };
 
+template<typename T> struct pure_virtual_dtor_template {
+  virtual ~pure_virtual_dtor_template() = 0;
+};
+template<typename T> pure_virtual_dtor_template<T>::~pure_virtual_dtor_template() {}
+template struct pure_virtual_dtor_template<int>;
+
+template<typename T> struct pure_virtual_dtor_template_inline {
+    virtual ~pure_virtual_dtor_template_inline() = 0 {}
+    // expected-warning at -1 2{{function definition with pure-specifier is a Microsoft extension}}
+};
+template struct pure_virtual_dtor_template_inline<int>;
+// expected-note at -1 {{in instantiation of member function}}
 
 int main () {
   // Necessary to force instantiation in -fdelayed-template-parsing mode.




More information about the cfe-commits mailing list