Bug 24479 – [REG2.104] Error on getAttributes on getOverloads of templates
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-04-03T22:46:21Z
Last change time
2024-04-23T14:24:14Z
Keywords
industry, pull, rejects-valid
Assigned to
No Owner
Creator
johanengelen
Comments
Comment #0 by johanengelen — 2024-04-03T22:46:21Z
Testcase, https://d.godbolt.org/z/cheqP1eof:
```
import std.meta : Filter;
struct S {
S opBinary(string op: "-")(S rhs) const pure nothrow @nogc {
return rhs;
}
S opBinary(string op: "*")(S dur) const pure nothrow @nogc {
return dur;
}
}
private enum hasExternalUDA(alias A) = is(A == External) || is(typeof(A) == External);
void foo() {
static foreach (t; __traits(getOverloads, S, "opBinary", true)) {
static assert( Filter!(hasExternalUDA, __traits(getAttributes, t)).length == 0 );
}
static foreach (t; __traits(getOverloads, S, "opBinary", true))
static foreach(attr; __traits(getAttributes, t))
pragma(msg, attr);
static assert(__traits(getOverloads, S, "opBinary", true).length == 2);
alias A = __traits(getAttributes, __traits(getOverloads, S, "opBinary", true)[1]);
}
```
Fails (deprecations are errors!) since dlang 2.104, with deprecations:
```
<source>(16): Deprecation: `__traits(getAttributes)` may only be used for individual functions, not overload sets such as: `opBinary`
<source>(16): the result of `__traits(getOverloads)` may be used to select the desired function to extract attributes from
<source>(20): Deprecation: `__traits(getAttributes)` may only be used for individual functions, not overload sets such as: `opBinary`
<source>(20): the result of `__traits(getOverloads)` may be used to select the desired function to extract attributes from
<source>(24): Deprecation: `__traits(getAttributes)` may only be used for individual functions, not overload sets such as: `opBinary`
<source>(24): the result of `__traits(getOverloads)` may be used to select the desired function to extract attributes from
```
Loosely related to https://issues.dlang.org/show_bug.cgi?id=23966.
I don't know a workaround, because iterating with explicit indexing as suggested in 23966 also does not work (last line of testcase).
Comment #1 by issues.dlang — 2024-04-03T23:22:56Z
I would point out that making deprecations errors pretty much defeats their entire purpose vs just changing the code without a deprecation. They're supposed to inform you about code that you're going to need to change without immediately breaking your code. So, anyone compiling their code with -de is going to be getting errors when they're not supposed to - and it _will_ cause problems in some cases with generic code, because template constraints routinely test whether a particular piece of code compiles or not.
Of course, regardless of how deprecations are treated, there then needs to be a way to transform your code appropriately so that it no longer triggers the deprecation, but deprecations are only treated as errors if you choose to do so, and it's usually a bad idea to do so.
Comment #2 by dlang-bot — 2024-04-05T12:52:29Z
@RazvanN7 updated dlang/dmd pull request #16358 "Fix Issue 24479 - [REG2.104] Error on getAttributes on getOverloads of templates" fixing this issue:
- Fix Bugzilla Issue 24479 - [REG2.104] Error on getAttributes on getOverloads of templates
https://github.com/dlang/dmd/pull/16358
Comment #3 by dlang-bot — 2024-04-18T08:00:10Z
dlang/dmd pull request #16358 "Fix Issue 24479 - [REG2.104] Error on getAttributes on getOverloads of templates" was merged into stable:
- 2e5d85a28ce1254f443b9bcd323c8d821cb8fed8 by RazvanN7:
Fix Bugzilla Issue 24479 - [REG2.104] Error on getAttributes on getOverloads of templates
https://github.com/dlang/dmd/pull/16358
Comment #4 by dlang-bot — 2024-04-23T14:24:14Z
dlang/dmd pull request #16406 "Merge stable" was merged into master:
- 9ca4c29549f944b820bbffc3e7b94c6f5ac23b1e by RazvanN7:
Fix Bugzilla Issue 24479 - [REG2.104] Error on getAttributes on getOverloads of templates
https://github.com/dlang/dmd/pull/16406