I think following code should compile with and without -d switch.
test.d
----
void main(){}
void foo(T)(T t){} // line 3
deprecated struct S{}
deprecated void test()
{
S s;
foo(s); // line 10
// foo is instantiated with deprecated struct S.
}
command line
----
dmd -run test.d
output:
----
test.d(3): Error: struct test.S is deprecated
test.d(10): Error: template instance test.foo!(S) error instantiating
Comment #1 by smjg — 2012-03-01T09:10:41Z
It seems to me the compiler generates
void fooS(S t) {}
but once the time's come to semantically analyse the instance, it has forgotten what created it in the first place.
Perhaps what's needed is: If when semantically analysing a template instance a deprecated symbol is hit, flag the template instance as deprecated. Then only if non-deprecated code references it will an error be generated.
The complication is that the error shown to the user should be about the original deprecated symbol. This can be achieved by accommodating in the propagated deprecation flag a note of the original deprecation.
Comment #2 by razvan.nitu1305 — 2019-11-30T09:45:25Z
I cannot reproduce this in master git HEAD. Closing as WORKSFORME.
Comment #3 by moonlightsentinel — 2019-11-30T22:40:51Z
Verified with DMD-nightly on run.dlang.io.
Comment #4 by razvan.nitu1305 — 2019-12-02T11:44:15Z
Why did you reopen? I just verified with dmd, dmd-beta and dmd-nightly and it doesn;t output any errors.
Comment #5 by moonlightsentinel — 2019-12-02T11:59:49Z
dmd-nightly on run.dlan.io produces:
onlineapp.d(3): Deprecation: struct onlineapp.S is deprecated
It still issues a warning that S is deprecated while instantiating foo in a deprecated context (and hence fails to compile with -de).
This is a blocking issue when compiling phobos unittests with "-checkaction=context"[1] as it instantiates templates with cfloat, ...
[1] https://github.com/dlang/phobos/pull/7252
Comment #6 by dlang-bot — 2021-11-18T22:41:18Z
@MoonlightSentinel updated dlang/dmd pull request #10677 "Fix Issue 7619 - Broken deprecated feature with template function" fixing this issue:
- Fix Issue 7619 - Infer deprecated for template instances
Template instances may use deprecated symbols that were passed as
template parameters or selected based on an instance-specific condition.
Previously DMD raised deprecation messages for the deprecated symbol at
the point of instantiation AND substitution inside of the template code.
The latter is cannot be suppressed by using `deprecated` because that
will only apply to certain instantiations.
This commit changes the behavior to check whether a deprecated symbol
is used inside of a template instance and marks the instance as
`deprecated` if found. That way only the actual usage of the instance
will raise deprecation messages.
Ideally this should only apply to deprecated symbols that depend on the
template parameters but those dependencies are not traceable in general
(`static if`, `compiles`, ...).
https://github.com/dlang/dmd/pull/10677
Comment #7 by robert.schadek — 2024-12-13T17:58:50Z