[PATCH] D29707: Fix improper microsoft-pure-definition warning on template class

Rudy Pons via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 8 01:39:35 PST 2017


Ilod created this revision.

Clang emits a warning when using pure specifier =0 in function definition at class scope, which is 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 template class.
This fix it by instead of !FD->isOutOfLine() to detect the places where we must emit the warning.
This will fix https://llvm.org/bugs/show_bug.cgi?id=21334


https://reviews.llvm.org/D29707

Files:
  lib/Sema/SemaDecl.cpp
  test/Parser/MicrosoftExtensions.cpp


Index: test/Parser/MicrosoftExtensions.cpp
===================================================================
--- test/Parser/MicrosoftExtensions.cpp
+++ test/Parser/MicrosoftExtensions.cpp
@@ -290,6 +290,17 @@
   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 {{function definition with pure-specifier is a Microsoft extension}} expected-warning {{function definition with pure-specifier is a Microsoft extension}}
+};
+template struct pure_virtual_dtor_template_inline<int>;// expected-note {{in instantiation of member function}}
+
 
 int main () {
   // Necessary to force instantiation in -fdelayed-template-parsing mode.
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -12025,7 +12025,7 @@
 
     // 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()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29707.87611.patch
Type: text/x-patch
Size: 1712 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170208/a5c6e9fb/attachment.bin>


More information about the cfe-commits mailing list