https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109792

            Bug ID: 109792
           Summary: RFE: Warn about misuse of "pure" attribute
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xry111 at gcc dot gnu.org
  Target Milestone: ---

I've spent several hours on https://github.com/systemd/systemd/pull/27595,
which fixes a wrong use of the "pure" attribute.  Consider the following:

$ cat t.c
extern int t(const char *, int *);

int t(const char *a, int *b)
{
  if (!a)
    return 114;

  *b = __builtin_strlen(a);
  return 0;
}

$ gcc t.c -S -Wall -Wextra -Werror && echo "no warning"
no warning
$ gcc t.c -S -Wall -Wextra -Werror -O1 && echo "no warning"
no warning
$ gcc t.c -S -Wall -Wextra -Werror -O2 && echo "no warning"
no warning
$ gcc t.c -S -Wall -Wextra -Werror -O3 && echo "no warning"
no warning
$ gcc t.c -S -Wall -Wextra -Werror -O3 -fanalyzer && echo "no warning"
no warning

If we had a warning here, it would have saved me several hours :).

Reply via email to