I have a following embedded system optimization case (simplified).
int main() { while (1) { // Do something if (unrecoverable_error) { __breakpoint(); while(1); } } } If the while (1); statement is replaced by return 0, the compiler invokes all the destructors due upon exit from main, (and for that matter generates the destructor code bloat) - both for main-local and global, even if the crt0 ultimately traps the CPU in a while(1); loop after all.
Thus, there is an advantage to judiciously use while(1); if one wants the system to intentionally hang.
Statically analyzing the code with -fanalyzer leads to (obvious) infinite loop error/warning.
How does one annotate that a specific instance of the infinite loop is indeed intentional?
I don't want to disable the infinite loop detection entirely (as it is possible that other parts of the code may contain bugs that lead to non-trivial infinite loops).
#pragma GCC diagnostic ignored "-Wanalyzer-infinite-loop"? You might want to surround it with#pragma GCC diagnostic push .... #pragma GCC diagnostic popstd::this_thread::yield".