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

            Bug ID: 80922
           Summary: #pragma diagnostic ignored  not honoured with -flto
           Product: gcc
           Version: 7.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thiago at kde dot org
  Target Milestone: ---

$ cat f1.cpp
#pragma GCC diagnostic ignored "-Wfree-nonheap-object"
void myfree(void *ptr)
{
    __builtin_free(ptr);
}

$ cat f2.cpp
void myfree(void *);

static char c;
int main()
{
    myfree(&c);
}

This code is intentionally bogus just to trigger the warning. The situation
that caused this was correct code, with a false positive warning I was trying
to suppress.

$ gcc -O2 -include f1.cpp f2.cpp
[no warning, as expected]

$ gcc -O2 -flto f1.cpp f2.cpp   
In function ‘myfree.constprop’,
    inlined from ‘main’ at f2.cpp:6:11:
f1.cpp:4:19: warning: attempt to free a non-heap object ‘c’
[-Wfree-nonheap-object]
     __builtin_free(ptr);
                   ^

Reply via email to