What's the point of g++ -Wreorder?

后端 未结 5 651
花落未央
花落未央 2020-11-29 17:49

The g++ -Wall option includes -Wreorder. What this option does is described below. It is not obvious to me why somebody would care (especially enough to turn this on by de

5条回答
  •  孤独总比滥情好
    2020-11-29 18:26

    Consider:

    struct A {
        int i;
        int j;
        A() : j(0), i(j) { }
    };
    

    Now i is initialized to some unknown value, not zero.

    Alternatively, the initialization of i may have some side effects for which the order is important. E.g.

    A(int n) : j(n++), i(n++) { }
    

提交回复
热议问题