Bug 19545 – __traits(compiles, X) false positive, further uses of X succeed but don't link

Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-01-03T16:07:45Z
Last change time
2023-04-04T12:02:00Z
Keywords
accepts-invalid, industry, wrong-code
Assigned to
No Owner
Creator
John Colvin
See also
https://issues.dlang.org/show_bug.cgi?id=19091

Comments

Comment #0 by john.loughran.colvin — 2019-01-03T16:07:45Z
import std.range, std.regex; void main() { //pragma(msg, __traits(compiles, inputRangeObject(RegexMatch!string.init))); inputRangeObject(RegexMatch!string.init); } /dlang/dmd/linux/bin64/../../src/phobos/std/range/primitives.d(2023): Error: static assert: "Cannot move front of a range with a postblit and an rvalue front." /dlang/dmd/linux/bin64/../../src/phobos/std/range/interfaces.d(379): instantiated from here: moveFront!(RegexMatch!string) /dlang/dmd/linux/bin64/../../src/phobos/std/range/interfaces.d(488): instantiated from here: InputRangeObject!(RegexMatch!string) onlineapp.d(5): instantiated from here: inputRangeObject!(RegexMatch!string) uncomment the pragma and you get true /dlang/dmd/linux/bin64/../../src/phobos/std/range/interfaces.d:497: error: undefined reference to '_D3std5range10interfaces__T16InputRangeObjectTS3std5regex__T10RegexMatchTAyaZQrZQCb7__ClassZ' /dlang/dmd/linux/bin64/../../src/phobos/std/range/interfaces.d:497: error: undefined reference to '_D3std5range10interfaces__T16InputRangeObjectTSQBt5regex__T10RegexMatchTAyaZQrZQCa6__ctorMFNfQBvZCQDsQDrQDo__TQDfTQCqZQDn' collect2: error: ld returned 1 exit status Error: linker exited with status 1
Comment #1 by john.loughran.colvin — 2019-01-07T11:35:03Z
void main() { pragma(msg, __traits(compiles, inputRangeObject(RegexMatch!string.init))); inputRangeObject(RegexMatch!string.init); } struct RegexMatch(T) { } class InputRangeObject(R) { this(R) { } R front() { } } InputRangeObject!R inputRangeObject(R)(R range) { return new InputRangeObject!R(range); } I've tried bisecting to find when in the history this started to go wrong, but it's hard (old dmds don't necessarily build on linux any more due to missing gcc headers). Here is the output from run.dlang.io, which suggests that there was a problem existing before 2.060, because while there it doesn't mistakenly continue with compilation it still reports `true` when it should say `false`: Up to 2.060 : Failure with output: ----- true onlineapp.d(17): Error: function onlineapp.InputRangeObject!(RegexMatch!(string)).InputRangeObject.front has no return statement, but is expected to return a value of type RegexMatch!(string) ----- 2.061 : Failure with output: ----- true onlineapp.o: In function `_D9onlineapp68__T16inputRangeObjectTS9onlineapp20__T10RegexMatchTAyaZ10RegexMatchZ16inputRangeObjectFS9onlineapp20__T10RegexMatchTAyaZ10RegexMatchZC9onlineapp68__T16InputRangeObjectTS9onlineapp20__T10RegexMatchTAyaZ10RegexMatchZ16InputRangeObject': /sandbox/onlineapp.d:24: undefined reference to `_D9onlineapp68__T16InputRangeObjectTS9onlineapp20__T10RegexMatchTAyaZ10RegexMatchZ16InputRangeObject7__ClassZ' /sandbox/onlineapp.d:24: undefined reference to `_D9onlineapp68__T16InputRangeObjectTS9onlineapp20__T10RegexMatchTAyaZ10RegexMatchZ16InputRangeObject6__ctorMFS9onlineapp20__T10RegexMatchTAyaZ10RegexMatchZC9onlineapp68__T16InputRangeObjectTS9onlineapp20__T10RegexMatchTAyaZ10RegexMatchZ16InputRangeObject' collect2: error: ld returned 1 exit status --- errorlevel 1 -----
Comment #2 by john.loughran.colvin — 2019-01-07T11:56:25Z
class C() { int foo() { } } C!() c()() { return new C!()(); } static assert(!__traits(compiles, c()));
Comment #3 by john.loughran.colvin — 2019-12-20T14:48:24Z
(In reply to John Colvin from comment #2) > class C() > { > int foo() { } > } > > C!() c()() > { > return new C!()(); > } > > static assert(!__traits(compiles, c())); not sure what this was about, maybe I pressed enter too early back then... The original bug is still there.
Comment #4 by default_357-line — 2020-10-09T14:29:03Z
Comment #5 by john.loughran.colvin — 2022-12-03T16:36:22Z
(In reply to John Colvin from comment #1) > void main() > { > pragma(msg, __traits(compiles, > inputRangeObject(RegexMatch!string.init))); > inputRangeObject(RegexMatch!string.init); > } > > struct RegexMatch(T) > { > } > > class InputRangeObject(R) > { > this(R) > { > } > > R front() > { > } > } > > InputRangeObject!R inputRangeObject(R)(R range) > { > return new InputRangeObject!R(range); > } > > I've tried bisecting to find when in the history this started to go wrong, > but it's hard (old dmds don't necessarily build on linux any more due to > missing gcc headers). > > Here is the output from run.dlang.io, which suggests that there was a > problem existing before 2.060, because while there it doesn't mistakenly > continue with compilation it still reports `true` when it should say `false`: > > Up to 2.060 : Failure with output: > ----- > true > onlineapp.d(17): Error: function > onlineapp.InputRangeObject!(RegexMatch!(string)).InputRangeObject.front has > no return statement, but is expected to return a value of type > RegexMatch!(string) > ----- > > 2.061 : Failure with output: > ----- > true > onlineapp.o: In function > `_D9onlineapp68__T16inputRangeObjectTS9onlineapp20__T10RegexMatchTAyaZ10Regex > MatchZ16inputRangeObjectFS9onlineapp20__T10RegexMatchTAyaZ10RegexMatchZC9onli > neapp68__T16InputRangeObjectTS9onlineapp20__T10RegexMatchTAyaZ10RegexMatchZ16 > InputRangeObject': > /sandbox/onlineapp.d:24: undefined reference to > `_D9onlineapp68__T16InputRangeObjectTS9onlineapp20__T10RegexMatchTAyaZ10Regex > MatchZ16InputRangeObject7__ClassZ' > /sandbox/onlineapp.d:24: undefined reference to > `_D9onlineapp68__T16InputRangeObjectTS9onlineapp20__T10RegexMatchTAyaZ10Regex > MatchZ16InputRangeObject6__ctorMFS9onlineapp20__T10RegexMatchTAyaZ10RegexMatc > hZC9onlineapp68__T16InputRangeObjectTS9onlineapp20__T10RegexMatchTAyaZ10Regex > MatchZ16InputRangeObject' > collect2: error: ld returned 1 exit status > --- errorlevel 1 > ----- This is the test case to pay attention to.
Comment #6 by salihdb — 2022-12-04T20:22:55Z
No error, result is true: void main() { pragma(msg, __traits(compiles, inputRangeObject(RegexMatch!string.init))); inputRangeObject(RegexMatch!string.init); } //import std.range, std.regex;/* struct RegexMatch(T){} class InputRangeObject(R){ this(R){} R front(){ return R.init; } } InputRangeObject!R inputRangeObject(R)(R range) { return new InputRangeObject!R(range); }//*/
Comment #7 by salihdb — 2022-12-04T20:23:08Z
No error, result is true: void main() { pragma(msg, __traits(compiles, inputRangeObject(RegexMatch!string.init))); inputRangeObject(RegexMatch!string.init); } //import std.range, std.regex;/* struct RegexMatch(T){} class InputRangeObject(R){ this(R){} R front(){ return R.init; } } InputRangeObject!R inputRangeObject(R)(R range) { return new InputRangeObject!R(range); }//*/
Comment #8 by john.loughran.colvin — 2022-12-10T11:39:15Z
(In reply to Salih Dincer from comment #6) > No error, result is true: > > void main() > { > pragma(msg, __traits(compiles, inputRangeObject(RegexMatch!string.init))); > inputRangeObject(RegexMatch!string.init); > } > //import std.range, std.regex;/* > struct RegexMatch(T){} > > class InputRangeObject(R){ > this(R){} > R front(){ return R.init; } > } > > InputRangeObject!R inputRangeObject(R)(R range) { > return new InputRangeObject!R(range); > }//*/ Yes, if the code is correct then there is no problem. But the code in my example is not correct and despite that, the traits compiles gives true and then in more recent compilers the code does compile but then can’t link.
Comment #9 by razvan.nitu1305 — 2023-04-04T12:02:00Z
This is a duplicate of 15459. Known issue: the template instance is cached even though it had errors. *** This issue has been marked as a duplicate of issue 15459 ***