https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115237
Bug ID: 115237 Summary: -Wsuggest-attribute=pure false positive for obviously non-pure function Product: gcc Version: 14.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: eggert at cs dot ucla.edu Target Milestone: --- This is gcc (GCC) 14.1.1 20240507 (Red Hat 14.1.1-1) on x86-64. I ran into this problem when compiling tzcode; this is a stripped-down version of the problem. Compile the following with 'gcc -O2 -Wsuggest-attribute=pure -S t.i': _Noreturn void error (); int unite (int a, int b) { int sum; if (a & b) error (); return a | b; } GCC complains: t.i: In function ‘unite’: t.i:4:3: warning: function might be candidate for attribute ‘pure’ if it is known to return normally [-Wsuggest-attribute=pure] 4 | unite (int a, int b) | ^~~~~ However, an important goal of the function is to report an error and exit if a&b is nonzero. The function must not be pure, because pure functions must return; they cannot exit or longjmp out or whatever. So this warning is clearly incorrect. I suggest suppressing the warning if the function that might call a noreturn function.