DeclarationName for C++ destructor

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

DeclarationName for C++ destructor

Lei Zhang
Hi clang,

After read some code relevant to DeclarationName, i have a little
problem about it.

For some C++ destructor(compile generated?), the base class (have some
virtual member) destructor and the derived class destructor have the
same DeclarationName.

Examples:

class base {

  virtual void foo() const {}

};



class child: public base {

  void foo() {}

};

if i use LookupPtr to find declarations in the base class with the
derived class destructor's DeclarationName, i will get the base class
destructor. Is this expected? If so,  what does this for?

--
Best regards!

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

Re: DeclarationName for C++ destructor

Sean Hunt-2
On Mon, Oct 10, 2011 at 23:40, 章磊 <[hidden email]> wrote:
Hi clang,

After read some code relevant to DeclarationName, i have a little
problem about it.

For some C++ destructor(compile generated?), the base class (have some
virtual member) destructor and the derived class destructor have the
same DeclarationName.

Examples:

class base {

 virtual void foo() const {}

};



class child: public base {

 void foo() {}

};

if i use LookupPtr to find declarations in the base class with the
derived class destructor's DeclarationName, i will get the base class
destructor. Is this expected? If so,  what does this for?

That doesn't sound quite right, but in any case, you shouldn't be using name lookup to find a destructor. Use Sema::LookupDestructor instead.

Sean

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

Re: DeclarationName for C++ destructor

Lei Zhang
Hi Sean,

Thank you for your reply.

I want to do some check to C++ override over all the methoddecls, but
when i try to do this in FindOverridenMethod which use name lookup to
find methoddecls with the same DeclarationName, I got the problem.

According to what you say, maybe i should treat dtor(ctor,
operator...) particularly.

2011/10/11, Sean Hunt <[hidden email]>:

> On Mon, Oct 10, 2011 at 23:40, 章磊 <[hidden email]> wrote:
>
>> Hi clang,
>>
>> After read some code relevant to DeclarationName, i have a little
>> problem about it.
>>
>> For some C++ destructor(compile generated?), the base class (have some
>> virtual member) destructor and the derived class destructor have the
>> same DeclarationName.
>>
>> Examples:
>>
>> class base {
>>
>>  virtual void foo() const {}
>>
>> };
>>
>>
>>
>> class child: public base {
>>
>>  void foo() {}
>>
>> };
>>
>> if i use LookupPtr to find declarations in the base class with the
>> derived class destructor's DeclarationName, i will get the base class
>> destructor. Is this expected? If so,  what does this for?
>>
>
> That doesn't sound quite right, but in any case, you shouldn't be using name
> lookup to find a destructor. Use Sema::LookupDestructor instead.
>
> Sean
>

--
Best regards!

Lei Zhang


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