[cfe-dev] Detecting an out-of-class defaulted method

via cfe-dev cfe-dev at lists.llvm.org
Tue Aug 31 15:16:59 PDT 2021


Clang AST novice here...

I have a CXXMethodDecl*, and I'm trying to determine whether it is
(a) marked `= default` in the class declaration,
(b) not `= default` in the class declaration, but `= default` in
    the outside-the-class definition, or
(c) neither.

Currently I'm doing this:

  if (Method->isExplicitlyDefaulted()) {
    if (Method->isUserProvided())
      defaulted_out_of_class;
    else
      defaulted_in_class;
  } else
    not_defaulted;

and I have a test case like

class foo {
  foo() = default;
  ~foo();
};
foo::~foo() = default;

The ctor is going through the defaulted_in_class path, but
the dtor is going through the not_defaulted path.

I've tried `Method->getCanonicalDecl()` instead of just `Method`
but the results are the same.

Any guidances/assistance appreciated!
Thanks,
--paulr



More information about the cfe-dev mailing list