GCC bug? Chaining methods, broken sequence point

后端 未结 3 2179
春和景丽
春和景丽 2021-02-19 03:26

I\'ve been debugging a program for some time, and eventually found the error was due to a reference not being updated as I thought it would be.

Here\'s a example that sh

3条回答
  •  故里飘歌
    2021-02-19 04:13

    [too long for a comment:]

    If adding

    Test& add(int& i, const int toadd)
    {
      i += toadd;
      return *this;
    }
    

    This call

    t.set(i).add(i, 5).print(i);
    

    returns

    15
    

    From this I conclude that the culprit is the i + 5 as parameter to print.

提交回复
热议问题