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

            Bug ID: 66098
           Summary: #pragma diagnostic 'ignored' not fully undone by pop
                    for strict-overflow
           Product: gcc
           Version: 5.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dd0t at users dot sourceforge.net
  Target Milestone: ---

Created attachment 35516
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35516&action=edit
Repro case with description

Attached is a sample that uses #pragma diagnostic push, ignored, pop to
temporarily disable a strict-overflow warning in a compilation with -Werror .
As expected the warning is suppressed so no error is created. However the pop
does not seem to fully restore the state to before the push. Triggering another
strict-overflow warning afterwards will produce the expected warning but even
though -Werror is enabled will not result in an error.

This behavior is present in gcc and g++ 5.1.0 and 5.1.1. With 4.9.2 however the
sample results in the expected error due to -Werror so this looks like a
regression.

// gcc -fstrict-overflow -Wstrict-overflow -Werror pop.c
// g++ -fstrict-overflow -Wstrict-overflow -Werror pop.c
//
// Incorrectly compiles with warning in g++/gcc 5.1.0 / 5.1.1
// Correctly shows error with 4.9.2.

void testing2() {
#pragma GCC diagnostic push
// Some of this pragma's change leaves the push/pop scope in some way.
// Only if it's commented out does the warning in testing3
// correctly produce an error. The pop seems to only partially
// undo it so that the error still becomes visible as a warning.
// If pop didn't do anything nothing should be visible.
#pragma GCC diagnostic ignored "-Wstrict-overflow"
        int j = 4;
        j + 4 < j;
#pragma GCC diagnostic pop
}

void testing3() {
    int k = 4;
    k + 4 < k;
}

int main() {
    testing2();
    testing3();

    return 0;
}

Reply via email to