Bug 20417 – __traits(compiles) returns false result if expression is not wrapped inside a lambda while typeof works correctly

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-11-26T16:29:29Z
Last change time
2019-11-29T10:36:57Z
Keywords
pull
Assigned to
No Owner
Creator
Suleyman Sahmi (سليمان السهمي)

Comments

Comment #0 by sahmi.soulaimane — 2019-11-26T16:29:29Z
Test case: ``` struct A { ~this(); } void f(A, int); A a(); int i(); pragma(msg, __traits(compiles, { f(a, i); })); // true pragma(msg, __traits(compiles, f(a, i))); // false pragma(msg, __traits(compiles, typeof({ f(a, i); }))); // true pragma(msg, __traits(compiles, typeof(f(a, i)))); // true ``` output: --- true false true true --- expected: --- true true true true ---
Comment #1 by razvan.nitu1305 — 2019-11-28T14:26:09Z
It seems that for some reason, when S has a destructor it tries to interpret the calls to a and i and it cannot do that because the functions have no bodies (compiles trait failes). However, I have no idea why it is trying to interpret those calls.
Comment #2 by dlang-bot — 2019-11-28T14:56:09Z
@SSoulaimane created dlang/dmd pull request #10626 "Fix issue 20417 - Do not run ctfe for temporaries inside __traits(compiles)" fixing this issue: - Fix issue 20417 - Do not run ctfe for temporaries inside __traits(compiles) https://github.com/dlang/dmd/pull/10626
Comment #3 by dlang-bot — 2019-11-29T10:36:57Z
dlang/dmd pull request #10626 "Fix issue 20417 - Do not run ctfe for temporaries inside __traits(compiles)" was merged into master: - 4ec3e6b8b1f3792b7036dde008539e8904d80ad6 by سليمان السهمي (Suleyman Sahmi): Fix issue 20417 - Do not run ctfe for temporaries inside __traits(compiles) https://github.com/dlang/dmd/pull/10626