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

            Bug ID: 79691
           Summary: -Wformat-truncation suppressed by (and only by) -Og
           Product: gcc
           Version: 7.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sbergman at redhat dot com
  Target Milestone: ---

At least with a recent GCC 7 trunk build ("gcc (GCC) 7.0.1 20170221
(experimental)"), I noticed that -Wformat-truncation warnings happen to
not be emitted if and only if -Og is given:

> $ cat test.c
> #include <stdio.h>
> int main() {
>     char buf[3];
>     snprintf(buf, sizeof buf, "%s", "foo");
>     return 0;
> }
> $ gcc -Wformat-truncation -Og ~/test.c
> $ gcc -Wformat-truncation -O ~/test.c
> test.c: In function ‘main’:
> test.c:4:34: warning: ‘snprintf’ output truncated before the last
> format character [-Wformat-truncation=]
>      snprintf(buf, sizeof buf, "%s", "foo");
>                                   ^
> test.c:4:5: note: ‘snprintf’ output 4 bytes into a destination of size 3
>      snprintf(buf, sizeof buf, "%s", "foo");
>      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Any other optimization level (-O0..3/s/fast) does emit the warning.

(See mail thread starting at <https://gcc.gnu.org/ml/gcc/2017-02/msg00103.html>
"New GCC 7 -Wformat-truncation suppressed by (and only by) -Og?".)

Reply via email to