struct AAA
{
unsigned int i0;
unsigned int i1;
unsigned int i2;
AAA() { i0 = 0; i1 = 0; i2 = 0; }
AAA(int a, int b, int c) {
i0 = a;
i1 = b;
i2 = c;
}
};
TEST(Cpp, autoplus) {
int i = 0;
AAA a(i++,i++,i++);
EXPECT_EQ(a.i0, 2);
EXPECT_EQ(a.i1, 1);
EXPECT_EQ(a.i2, 0);
}
release测试不通过,i0 i1 i2 值都为0
debug通过,i0 i1 i2 值为2,1,0
原因分析:release优化导致的,release模式下,个人猜测是编译器先将i++复制给一个临时变量,int tmp = i++; 再用该临时变量创建AAA对象,从而导致结果不同