[cfe-dev] Is it a bug? clang doesn't generate "complete object constructor" code when the class contains pure virtual method.

Richard Smith richard at metafoo.co.uk
Mon Dec 10 16:20:20 PST 2012


On Mon, Dec 10, 2012 at 8:12 AM, Rafael EspĂ­ndola
<rafael.espindola at gmail.com> wrote:
>> I'm not sure whether this is a clang bug, but could anyone tell me whether
>> clang acts properly? Is there any standard that defines whether compiler
>> shouldn't generate C1 version construct when the class has pure virtual
>> method?
>
>
> I looked at http://mentorembedded.github.com/cxx-abi/abi.html, but
> could not find anything.
>
>
>> ===============================
>> class A
>> {
>> public:
>>     A();
>> };
>>
>> class B
>> {
>> public:
>>     B();
>>     virtual void Foo() = 0;
>> };
>>
>> A::A() {};
>> B::B() {};
>> ===============================
>>
>
> ...
>
>> 5. If I remove "= 0" from Foo() to change it from pure virtual to virtual
>> method, clang will generate C1 constructor.
>>
>
> Do you see a case where we get a undefined reference to __ZN1BC1Ev?
> Since the class has a pure virtual method, I would expect that it is
> only constructed as part of building a larger object, and so this is a
> valid clang optimization, no?

This was also reported as PR14557 (in future, please don't fragment
the discussion like that!). This seems like a valid optimization to
me.




More information about the cfe-dev mailing list