Bug 16312 – "Error: Overlapping fields" caused by use of deprecated features in referred to fields

Status
NEW
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-07-22T20:48:34Z
Last change time
2024-12-13T18:49:05Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Marco Leise
Moved to GitHub: dmd#19162 →

Comments

Comment #0 by Marco.Leise — 2016-07-22T20:48:34Z
The compiler sees fields as overlapping when there are certain types of deprecated features involved in the types of those fields. The two trigger features I could make out are using full symbol paths to bypass imports (i.e. using core.stdc.stdlib.free without importing core.stdc.stdlib) and providing a struct ctor with all arguments having defaults. If such a "deprecated" struct is then used with other fields in an aggregate in a way it would not be allowed for overlapping fields, an error is printed. Here is a short example: struct Deprecated { this(int i = 0) {} } class Bogus { Deprecated* a = null; int seems_to_overlap = 0; } Deprecation: constructor app.Deprecated.this all parameters have default arguments, but structs cannot have default constructors. Error: overlapping default initialization for field a and seems_to_overlap Whether or not the compiler would actually silently overlap the two fields under other circumstances is not known to me. Related in some way: https://issues.dlang.org/show_bug.cgi?id=15498 (Unhelpful error message "destructors, postblits and invariants are not allowed in overlapping fields")
Comment #1 by mathias.lang — 2016-07-22T21:18:37Z
Note: Only when compiled with `-de`. They are two things at play here: - First, when the compiler encounter an error, it 'poison' the AST node. That can lead to wrong error messages in places not adjusted to deal with the poisoning. - Second, the compiler treat a non-fatal error (e.g. a warning when `-w` is provided or a deprecation when `-de` is provided) as a fatal one. This can have extremely dangerous consequences, e.g. the following will still compiles, just have different behaviour: ``` class Deprecated { int j; this (T) (T i) { this.j = (i, T.init); } } template Foo (T) if (__traits(compiles, { T a = new T(42); })) { enum Foo = "First instance"; } template Foo (T) if (!__traits(compiles, { T a = new T(42); })) { enum Foo = "Second instance"; } pragma(msg, Foo!(Deprecated)); ``` The second bug is well known, so I suppose this ER is about the first point ?
Comment #2 by Marco.Leise — 2016-07-23T16:11:48Z
This report is about the first point, yes. Even if treated as an error, "deprecated" means the compiler can still handle the situation. I suggest, not to poison the AST for "deprecated as error" and "warning as error", but just print the error and continue compilation as normal. (And return -1 from main.) Does that seem feasible?
Comment #3 by Marco.Leise — 2016-07-23T17:31:36Z
I just got the overlapping fields error after a bunch of "undefined identifier" errors. So it doesn't only happen after deprecated features are used. It happens with both dmd 2.069 and 2.071.1 at least. Other compilers were not tested.
Comment #4 by robert.schadek — 2024-12-13T18:49:05Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19162 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB