Assignment in C++ occurs despite exception on the right side

前端 未结 3 1354
遥遥无期
遥遥无期 2021-02-03 17:05

I have some (C++14) code that looks like this:

map> junk;
for (int id : GenerateIds()) {
    try {
        set stuff =         


        
3条回答
  •  青春惊慌失措
    2021-02-03 17:26

    Before C++17 there was no sequencing between the left- and right-hand side of assignment operators.

    It's first in C++17 that explicit sequencing was introduced (right-hand side is evaluated first).

    That means the evaluation order is unspecified, which means it's up to the implementation to perform the evaluation in the order in which it wants, and in this case it evaluates the left-hand side first.

    See this evaluation order reference for more details (especially point 20).

提交回复
热议问题