Bug 20730 – [REG 2.091] __traits(compiles) fails if any ungagged errors occurred in compilation
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-04-12T11:45:58Z
Last change time
2020-04-12T18:43:42Z
Keywords
pull
Assigned to
No Owner
Creator
Iain Buclaw
Comments
Comment #0 by ibuclaw — 2020-04-12T11:45:58Z
Caused by: https://github.com/dlang/dmd/pull/10711
Test:
---
import xstd.stdio;
void test21()
{
auto f = File().byLine;
}
void main()
{
test23();
}
---
---
T atomicOp(string op, T, V1)(ref shared T val, V1 mod)
if (__traits(compiles, mixin("*cast(T*)&val" ~ op ~ "mod")))
{
return val;
}
struct File
{
shared uint refs;
this(this)
{
atomicOp!"+="(refs, 1);
}
struct ByLineImpl(Char)
{
File file;
char[] line;
}
auto byLine()
{
return ByLineImpl!char();
}
}
---
Expected output:
---
Error: undefined identifier `test23`, did you mean function `test21`?
---
Actual output:
---
Error: undefined identifier `test23`, did you mean function `test21`?
Error: template `stdio.atomicOp` cannot deduce function from argument types `!("+=")(shared(uint), int)`, candidates are:
xstd/stdio.d(1): `atomicOp(string op, T, V1)(ref shared T val, V1 mod)`
with `op = "+=",
T = uint,
V1 = int`
must satisfy the following constraint:
` __traits(compiles, mixin("*cast(T*)&val" ~ op ~ "mod"))`
---
Fixing the first error makes the template instantiation error go away.
Comment #1 by dlang-bot — 2020-04-12T12:32:30Z
@ibuclaw created dlang/dmd pull request #11023 "fix Issue 20730 - [REG 2.091] __traits(compiles) fails if any ungagged errors occurred in compilation" fixing this issue:
- fix Issue 20730 - [REG 2.091] __traits(compiles) fails if any ungagged errors occurred in compilation
When running semantic on __traits(compiles), errors are gagged, so
there's little point checking the value of global.errors here.
If any real problems occurred, they can be dealt with by the endGagging
checks at the end of the function.
https://github.com/dlang/dmd/pull/11023
Comment #2 by dlang-bot — 2020-04-12T18:43:42Z
dlang/dmd pull request #11023 "fix Issue 20730 - [REG 2.091] __traits(compiles) fails if any ungagged errors occurred in compilation" was merged into stable:
- e8922ef9967772e659d03e5459bbf8993902de89 by Iain Buclaw:
fix Issue 20730 - [REG 2.091] __traits(compiles) fails if any ungagged errors occurred in compilation
When running semantic on __traits(compiles), errors are gagged, so
the saved errors count is global.gaggedErrors, and not global.errors.
So the condition always evaluated as true if any real errors occured
during compilation, and every subsequent __traits(compiles) errors too,
whether it is valid syntax or not.
https://github.com/dlang/dmd/pull/11023