Am Di., 6. Okt. 2020 um 23:06 Uhr schrieb Bruno Haible <br...@clisp.org>:
> Marc Nieper-Wißkirchen wrote: > > In file included from lib/gl_linked_list.c:29: > > lib/gl_linked_list.c: In function 'gl_linked_iterator_from_to': > > lib/gl_anylinked_list2.h:938:1: error: function might be candidate for > > attribute 'pure' if it is known to return normally > > [-Werror=suggest-attribute=pure] > > 938 | gl_linked_iterator_from_to (gl_list_t list, > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~ > > But no such warning in line 920? Makes no sense to me. The function is static and will be inlined everywhere so the static analyzer (in the relevant optimizing levels) doesn't seem to get to the point where it has to/can check whether the function is pure or not. > And a function that may invoke abort () does "affect observable state". This description of the a pure function does not seem to be accurate. When a function calls another function like abort that is marked with _Noreturn in a pure context, for the compiler the function can still be pure (but not const). It can eliminate a second call to the function with the same parameters. I am pretty sure that the warning of GCC in line 938 is correct. (It has to be conservative about this warning because you cannot mark a funciton non-pure.) (That GCC understands about _Noreturn in a pure context is important as otherwise the assert debugging facility becomes less usable.)