[cfe-dev] IsVirtual for destructors

Loïc Joly via cfe-dev cfe-dev at lists.llvm.org
Wed Jun 7 13:01:00 PDT 2017


Hello,

I've read the source code of the CXXMethodDecl::isVirtual function https://clang.llvm.org/doxygen/DeclCXX_8h_source.html#l01877


  bool isVirtual<https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html#a1f488b7521f08ced46dce05c44cab5c5>() const {
  CXXMethodDecl<https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html> *CD =
  cast<CXXMethodDecl>(const_cast<CXXMethodDecl<https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html>*>(this)->getCanonicalDecl<https://clang.llvm.org/doxygen/IndexingContext_8cpp.html#a35cbf522872a806ddf6a0b69a764bb33>());

  // Member function is virtual if it is marked explicitly so, or if it is
  // declared in __interface -- then it is automatically pure virtual.
  if (CD->isVirtualAsWritten<https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html#adb6ca6181b0ca64bd743d64ff8ad1bb6>() || CD->isPure<https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html#a0a90a6ef82dce606a80309e43970aee9>())
  return true;

  return (CD->begin_overridden_methods<https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html#a72bcbca3667d9efbc8a031a90472f2fe>() != CD->end_overridden_methods<https://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html#aeecab4c03e5f81230747509b7e70e93e>());
  }


In code such as the following:

struct Base
{
    virtual ~Base();
};

struct Derived :Base
{
    ~Derived();
};


The derived class destructor is virtual, but it is not virtual as written, not pure, and it appears that the list of overridden methods is empty. So the isVirtual function returns false.

Shall I fill a bug report?

---
Loïc


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170607/79b75b3d/attachment.html>


More information about the cfe-dev mailing list