[Bug c++/78826] New: jump bypasses non-POD

2016-12-15 Thread aurzenligl at gmail dot com
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)

[Bug c++/78826] jump bypasses non-POD

2016-12-16 Thread aurzenligl at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78826

--- Comment #3 from Krzysztof Laskowski  ---
(In reply to Jonathan Wakely from comment #2)
> I assume GCC 4.5 stopped diagnosing it due to the revised specification
> which only cares about trivial constructor or trivial destructor, not
> PODness.
I couldn't actually find any clause allowing jump over trivially constructed
variable in ISO/IEC 14882:1998 nor ISO/IEC 14882:2003. Moreover, icc (13, 16,
17) and clang (3.0-3.9) warn and err, respectively, on example.

It seems to correlate with introducing c++0x support in gcc.
https://gcc.gnu.org/gcc-4.5/changes.html
"Diagnostics that used to complain about passing non-POD types to ... or
jumping past the declaration of a non-POD variable now check for triviality
rather than PODness, as per C++0x."

> Giving a diagnostic here would just be pedantic and unhelpful.
I agree it's harmless to bypass trivially constructed variable. Does it mean
that it's a deliberate deviation from standard for the sake of ease of c++11
implementation at the cost of portability/conformance?