test for unorderd init

This commit is contained in:
MITSUNARI Shigeo 2012-12-04 16:12:59 +09:00
parent be5d47c144
commit a57fdb0f10
4 changed files with 35 additions and 2 deletions

View file

@ -1,6 +1,27 @@
#pragma once #pragma once
#include <stdio.h> #include <stdio.h>
struct Reg {
int r_;
Reg(int r) : r_(r) {}
};
inline const Reg& getReg0() { static const Reg r(0); return r; }
inline const Reg& getReg1() { static const Reg r(1); return r; }
inline const Reg& getReg2() { static const Reg r(2); return r; }
static const Reg& r0 = getReg0();
static const Reg& r1 = getReg1();
static const Reg& r2 = getReg2();
inline void putReg()
{
puts("putReg");
printf("r0=%p, %d\n", &r0, r0.r_);
printf("r0=%p, %d\n", &r0, r1.r_);
printf("r0=%p, %d\n", &r0, r2.r_);
}
struct A { struct A {
int a; int a;
A() A()
@ -30,11 +51,13 @@ typedef XT<0> X;
void init(); void init();
static struct Init { struct Init {
Init() Init()
{ {
puts("Init"); puts("Init");
init(); init();
putReg();
} }
} s_init; };
static Init s_init;

View file

@ -1,5 +1,9 @@
#include <stdio.h> #include <stdio.h>
static const struct XXX {
XXX() { puts("XXX"); }
} s_sss;
struct A { struct A {
int aaa; int aaa;
A() A()
@ -35,9 +39,13 @@ static struct Init {
} }
} s_init; } s_init;
int f() { puts("f"); return 4; }
static const int r = f();
int main() int main()
{ {
puts("main"); puts("main");
printf("r=%d\n", r);
X::sss.put(); X::sss.put();
} }

View file

@ -4,5 +4,6 @@ int main()
{ {
puts("main"); puts("main");
X::a.put(); X::a.put();
putReg();
} }

View file

@ -7,6 +7,7 @@ void init()
if (!init) return; if (!init) return;
init = false; init = false;
X::a.put(); X::a.put();
putReg();
} }