85 lines · c
1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5 6#include <stdio.h>7#include <Block.h>8 9// CONFIG C++ rdar://6243400,rdar://628936710 11 12int constructors = 0;13int destructors = 0;14 15 16#define CONST const17 18class TestObject19{20public:21 TestObject(CONST TestObject& inObj);22 TestObject();23 ~TestObject();24 25 TestObject& operator=(CONST TestObject& inObj);26 27 int version() CONST { return _version; }28private:29 mutable int _version;30};31 32TestObject::TestObject(CONST TestObject& inObj)33 34{35 ++constructors;36 _version = inObj._version;37 //printf("%p (%d) -- TestObject(const TestObject&) called\n", this, _version); 38}39 40 41TestObject::TestObject()42{43 _version = ++constructors;44 //printf("%p (%d) -- TestObject() called\n", this, _version); 45}46 47 48TestObject::~TestObject()49{50 //printf("%p -- ~TestObject() called\n", this);51 ++destructors;52}53 54 55TestObject& TestObject::operator=(CONST TestObject& inObj)56{57 //printf("%p -- operator= called\n", this);58 _version = inObj._version;59 return *this;60}61 62 63 64void testRoutine() {65 TestObject one;66 67 void (^b)(void) = ^{ printf("my const copy of one is %d\n", one.version()); };68}69 70 71 72int main(int argc, char *argv[]) {73 testRoutine();74 if (constructors == 0) {75 printf("No copy constructors!!!\n");76 return 1;77 }78 if (constructors != destructors) {79 printf("%d constructors but only %d destructors\n", constructors, destructors);80 return 1;81 }82 printf("%s:success\n", argv[0]);83 return 0;84}85