[cfe-dev] better way to test for explicit C++ constructor?
Kim Gräsman
kim.grasman at gmail.com
Tue Dec 11 14:41:36 PST 2012
Hi Peeter,
Glad it worked, but I wonder if you could get away with just
hasUserDeclaredConstructor?
As far as I understand it, that should be the same as what you're doing
below, if you're only interested in existence.
I would trust Eli more than I trust myself, though, so take this with a
grain of salt.
- Kim
On Tuesday, December 11, 2012, Peeter Joot wrote:
> Thanks Kim, that worked nicely:
>
> for ( CXXRecordDecl::ctor_iterator b = r->ctor_begin(), e =
> r->ctor_end() ;
> b != e ; ++b )
> {
> if ( !b->isImplicitlyDefined() )
> {
> cout << r->getName().str() << " : CONSTRUCTOR" << endl ;
>
> break ;
> }
> }
>
> and is much cleaner.
>
> Peeter
>
> CXXRecordDecl has a ctor_begin/ctor_end pair, which return iterators
>> over all constructors.
>>
>> They are of type CXXConstructorDecl, and that class in turn has an
>> isImplicitlyDefined method you can use to check whether it's
>> user-written or not.
>>
>> You should be able to loop over the RecordDecl's constructors and
>> count the ones not implicitly defined.
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121211/494548ad/attachment.html>
More information about the cfe-dev
mailing list