[Bug c++/77592] gcc accepts delegated constructor with circular reference

2016-09-14 Thread gawain.bolton at free dot fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77592

--- Comment #3 from Gawain Bolton  ---
You are absolutely right, it is my program that seg faults and not GCC.

As you suggest, it would be great if GCC could give a diagnostic for delegated
constructor circular references.

[Bug c++/77592] gcc accepts delegated constructor with circular reference

2016-09-14 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77592

--- Comment #2 from Jonathan Wakely  ---
(In reply to Gawain Bolton from comment #0)
> Compilation segfaults using gcc v5.3, v6.1 and gcc HEAD 7.0.0 20160913

Compilation works fine, the executable segfaults, due to a stack overflow.

The standard says your code is "ill-formed, no diagnostic required" so
compilers aren't required to reject the code, but it would be nice to diagnose
it.

Clang does:

circ.cc:10:7: error: constructor for 'T' creates a delegation cycle
[-Wdelegating-ctor-cycles]
: T(i,s)
  ^
circ.cc:3:5: note: it delegates to
T(const int i,
^
circ.cc:8:5: note: which delegates to
T(const char * s,
^


And EDG does:

"circ.cc", line 10: error: constructor delegates directly or indirectly to
  itself
  : T(i,s)
^

[Bug c++/77592] gcc accepts delegated constructor with circular reference

2016-09-14 Thread trippels at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77592

Markus Trippelsdorf  changed:

   What|Removed |Added

   Keywords||accepts-invalid
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2016-09-14
 CC||trippels at gcc dot gnu.org
Summary|GCC: Compile failures with  |gcc accepts delegated
   |delegated constructor   |constructor with circular
   |circular reference  |reference
 Ever confirmed|0   |1

--- Comment #1 from Markus Trippelsdorf  ---
The resulting binary segfaults not gcc.

markus@x4 /tmp % g++ seg.ii
markus@x4 /tmp % icpc seg.ii
seg.ii(4): error: constructor delegates directly or indirectly to itself
T(const char *s, const int i) : T(i, s) {}
^

compilation aborted for seg.ii (code 2)

markus@x4 /tmp % clang++ seg.ii
seg.ii:4:35: error: constructor for 'T' creates a delegation cycle
[-Wdelegating-ctor-cycles]
  T(const char *s, const int i) : T(i, s) {}
  ^
seg.ii:2:3: note: it delegates to
  T(const int i, const char *s) : T(s, i) {}
  ^
seg.ii:4:3: note: which delegates to
  T(const char *s, const int i) : T(i, s) {}
  ^
1 error generated.