Ambiguous if and else branches: Is the behaviour defined?

前端 未结 5 1906
既然无缘
既然无缘 2021-01-18 11:33

I recently came accross some C++ code like the following:

if(test_1)
    if(test_2)
    {
         // Do stuff
    }
    else
       exit(0);
5条回答
  •  生来不讨喜
    2021-01-18 12:21

    Yes its not ambiguous, as the rules state where it is applied, but my GCC C++ compiler still gives a warning stating it is :

    /brainModule/BrainModule.cpp: In function ‘void failExpiredPendingAndRunning()’: ../brainModule/BrainModule.cpp:158:16: warning: suggest explicit braces to avoid ambiguous ‘else’ [-Wparentheses] if (job->isExpired() == false)

    g++ (Raspbian 6.3.0-18+rpi1+deb9u1) 6.3.0 20170516

提交回复
热议问题