[LLVMbugs] [Bug 16198] New: The constructor of C++ class is called twice when C++ object is an instance of Objective-C class.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Jun 2 14:42:59 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=16198

            Bug ID: 16198
           Summary: The constructor of C++ class is called twice when C++
                    object is an instance of Objective-C class.
           Product: clang
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: konevaanna2012 at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

I have installed the latest version of Xcode 4.6.2. And when I use the compiler
Apple LLVM 4.2, I get a strange thing. Imagine we have this code sample code,
displayed below.

main.mm:

#import <Foundation/Foundation.h>
#import "ObjCClass.h"

int main(int argc, const char * argv[])
{
    ObjCClass *obj = [[ObjCClass alloc]init];

    [obj SomeObjCMethod];

    [obj release];

    return 0;
}



ObjCClass.h:

#import <Foundation/Foundation.h>
#include "CppClass.h"

@interface ObjCClass : NSObject
{
    CppClass cppClass;
}
- (id)init;
- (void)SomeObjCMethod;
@end


ObjCClass.mm:

#import "ObjCClass.h"

@implementation ObjCClass

- (id)init
{
    self = [super init];
    if (self != nil)
    {

    }
    return self;
}

- (void)SomeObjCMethod
{
    cppClass.someMethod(43);
}




CppClass.h:

class CppClass
{
public:
    CppClass();
    int someMethod(int param);
};


CppClass.cpp:

#include "CppClass.h"
#include <iostream>

using namespace std;

CppClass::CppClass()
{  

}

int CppClass::someMethod(int param)
{
    cout << "param = " << param << endl;
    return param;
}

When I run a program I see in a debugger that the constructor of C++ class
CppClass::CppClas is called twice for some reason. Could you, please, tell me,
is it a bug or maybe I don't understand anything? By the way, when I use GCC
with checkbox "Call C++ Default Ctors/Dtors in Objective-C" being checked this
constructor is called only once...

Regards,
Anna.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130602/150dea1b/attachment.html>


More information about the llvm-bugs mailing list