On 2024-06-05 08:32, Basil L. Contovounesios wrote:

It's also too bad that N2956 has this typo, and that it doesn't mention
GCC's returns-exactly-once constraints on pure and const functions.

Do you have a pointer to where this constraint is documented?  I'm not
sure what it means, and I can't find it in my copy of the gcc-13 manual.

It's not stated directly, but it's there. It should be documented better. I've confirmed it by compiling programs and looking at the code, and via messages from GCC implementers.

For example, compile this with 'gcc -O2 -S':

  int difftime (long, long) __attribute__ ((pure));

  int
  f ()
  {
    return difftime (42, 27) - difftime (42, 27);
  }

and you'll see that the calls to difftime are optimized away and f always returns 0. This optimization would be invalid if difftime did not return, or returned multiple times.

The C23 spec for [[unsequenced]] and [[reproducible]] does not mention this issue, which is a significant oversight.

Reply via email to