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

            Bug ID: 78826
           Summary: jump bypasses non-POD
           Product: gcc
           Version: 6.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aurzenligl at gmail dot com
  Target Milestone: ---

Compiler seems to break c++98 and c++03 standards by allowing to jump over
non-POD automatic local variable declaration.

// jump_bypasses_non_pod.cpp
struct empty {};
struct non_pod_in_cpp03 : public empty {};
void should_not_compile() {
    goto label;
    non_pod_in_cpp03 x;
label:
    (void)x;
}

If I get the standard right, non-aggregates (types with bases or
private/protected non-static data members) are non-PODs and jumping over them
is illegal:
    (C++03 6.7 §3) [stmt.dcl]
    (C++03 8.5.1 §1) [dcl.init.aggr]
    (C++03 9 §4) [class]

I'd expect that -pedantic compilation would at least issue a warning instead of
compiling ill-formed program silently:
    $ g++-6 -Wall -Wextra -std=c++98 -g -pedantic -c jump_bypasses_non_pod.cpp

Problem happens with both kinds of jumps:
    - goto to label
    - switch to case
Problem reproduces with both std flags:
    - -std=c++98
    - -std=c++03
Problem reproduces on a wide range of gcc releases:
    - gcc version 4.9.4 (Ubuntu 4.9.4-2ubuntu1~14.04.1) 
    - gcc version 5.4.1 20160904 (Ubuntu 5.4.1-2ubuntu1~14.04) 
    - gcc version 6.2.0 20160901 (Ubuntu 6.2.0-3ubuntu11~14.04)

Reply via email to