Implicitly defined special member functions

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Implicitly defined special member functions

Martin Vejnár-2
Hi,

I'm trying to use clang as a front end to a static analysis tool (Stanse,
http://stanse.fi.muni.cz/). For that purpose, I'd like to get special
member functions defined even if they are not used. Can I somehow achieve
that? (Note that I'm consuming the AST in HandleTranslationUnit of my
custom ASTConsumer.)

Furthermore, it seems that fn->isThisDeclarationADefinition() returns
false for default constructors and destructors even when the function is
used (and therefore implicitly defined). Is that correct? Shouldn't these
functions receive an empty CompoundStatement as their bodies?

Thanks in advance,
--
Martin

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Implicitly defined special member functions

Douglas Gregor

On Sep 17, 2010, at 4:55 AM, Martin Vejnár wrote:

> Hi,
>
> I'm trying to use clang as a front end to a static analysis tool (Stanse,
> http://stanse.fi.muni.cz/). For that purpose, I'd like to get special
> member functions defined even if they are not used. Can I somehow achieve
> that? (Note that I'm consuming the AST in HandleTranslationUnit of my
> custom ASTConsumer.)

You'll need to ask the Sema object for the constructors, destructors, and assignment operator, so that it will generate them.

> Furthermore, it seems that fn->isThisDeclarationADefinition() returns
> false for default constructors and destructors even when the function is
> used (and therefore implicitly defined). Is that correct? Shouldn't these
> functions receive an empty CompoundStatement as their bodies?


Yes, that would make sense. Care to submit a patch?

        - Doug
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Implicitly defined special member functions

Martin Vejnár
On 9/17/2010 8:46 PM, Douglas Gregor wrote:
> On Sep 17, 2010, at 4:55 AM, Martin Vejnár wrote:
>> I'm trying to use clang as a front end to a static analysis tool (Stanse,
>> http://stanse.fi.muni.cz/). For that purpose, I'd like to get special
>> member functions defined even if they are not used. Can I somehow achieve
>> that? (Note that I'm consuming the AST in HandleTranslationUnit of my
>> custom ASTConsumer.)
>
> You'll need to ask the Sema object for the constructors, destructors,
> and assignment operator, so that it will generate them.

Thanks, I've found the function Sema::MarkDeclarationReferenced, I'm
calling it on all methods of all CXXRecordDecls, and it seems to work
perfectly.

>> Furthermore, it seems that fn->isThisDeclarationADefinition() returns
>> false for default constructors and destructors even when the function is
>> used (and therefore implicitly defined). Is that correct? Shouldn't these
>> functions receive an empty CompoundStatement as their bodies?
>
> Yes, that would make sense. Care to submit a patch?

Attached.
--
Martin

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

smf_bodies.patch (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Implicitly defined special member functions

Douglas Gregor

On Sep 19, 2010, at 12:52 AM, Martin Vejnár wrote:

> On 9/17/2010 8:46 PM, Douglas Gregor wrote:
>> On Sep 17, 2010, at 4:55 AM, Martin Vejnár wrote:
>>> I'm trying to use clang as a front end to a static analysis tool (Stanse,
>>> http://stanse.fi.muni.cz/). For that purpose, I'd like to get special
>>> member functions defined even if they are not used. Can I somehow achieve
>>> that? (Note that I'm consuming the AST in HandleTranslationUnit of my
>>> custom ASTConsumer.)
>>
>> You'll need to ask the Sema object for the constructors, destructors,
>> and assignment operator, so that it will generate them.
>
> Thanks, I've found the function Sema::MarkDeclarationReferenced, I'm calling it on all methods of all CXXRecordDecls, and it seems to work perfectly.

Yes, that will force the creation of the method.

>>> Furthermore, it seems that fn->isThisDeclarationADefinition() returns
>>> false for default constructors and destructors even when the function is
>>> used (and therefore implicitly defined). Is that correct? Shouldn't these
>>> functions receive an empty CompoundStatement as their bodies?
>>
>> Yes, that would make sense. Care to submit a patch?
>
> Attached.

Thanks! Committed as r114329.

        - Doug
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev