cling/test/Prompt/initorder.C
Vassil Vassilev 1ae610b211 Fix savannah #99234.
The issue we experienced is that we couldn't pipe the output in the terminal.
The reason is that we were using llvm::outs() which closes explicitly the file
descriptor (thanks Axel for the help debugging).
We introduce our custom stream, which keeps the file descriptor open so that
we can use it in pipes. For debugging purposes, however we use/should use llvm::errs()

The lesson learned:
DONT USE LLVM::OUTS() ANYMORE!


git-svn-id: http://root.cern.ch/svn/root/trunk@48316 27541ba8-7e3a-0410-8455-c3a389f83636
2013-01-17 15:27:14 +00:00

46 lines
1.2 KiB
C

// RUN: cat %s | %cling | FileCheck %s
// Checks:
// Savannah #99210 https://savannah.cern.ch/bugs/index.php?99210
// Savannah #99234 https://savannah.cern.ch/bugs/?99234
// Let's start with simpler example pointing out the issue:
int i = 1; i++; int j = i;
j
// CHECK: (int) 2
extern "C" int printf(const char*,...);
.rawInput
class RAII {
public:
RAII(int i) { I = new int(i); printf("RAII%d\n", ++InstanceCount); };
int incr() { return ++(*I); }
int get() { return *I; }
~RAII() { delete I; printf("~RAII%d\n", InstanceCount--); }
private:
RAII(RAII&) {throw;};
RAII& operator=(RAII) {throw;}
int* I;
static int InstanceCount; // will notice object copy
};
int RAII::InstanceCount = 0;
.rawInput
// This works because each line ends up in a separate wrapper
RAII R(12); // CHECK: RAII1
R.get();
int res = R.incr() // CHECK: 13
// This does not work because the decls and their inits are run before the
// call to R2.incr(), i.e. the second statement in the line.
// Savannah #99210 https://savannah.cern.ch/bugs/index.php?99210
RAII R2(42);R2.incr();int res2 = R2.get()
// CHECK: RAII2
// CHECK: 43
.q
// CHECK: ~RAII2
// CHECK: ~RAII1
// Enforce that only two objects got ever constructed:
// CHECK-NOT: ~RAII0