Bug 7322 – Taking address of deprecated functions isn't refused

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-01-19T11:23:32Z
Last change time
2024-12-13T17:57:51Z
Keywords
accepts-invalid, pull
Assigned to
No Owner
Creator
bearophile_hugs
Moved to GitHub: dmd#18401 →

Comments

Comment #0 by bearophile_hugs — 2012-01-19T11:23:32Z
In DMD 2.058head std.string.rjustify is deprecated, so this program: import std.string; void main() { rjustify!string("hello", 10); } Gives the correct error message: test.d(3): Error: function std.string.rjustify!(string).rjustify is deprecated But this program gives no deprecated errors: import std.string; void main() { auto J = &rjustify!string; J("hello", 10); }
Comment #1 by yebblies — 2012-01-31T20:00:40Z
Comment #2 by github-bugzilla — 2012-07-17T00:09:11Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/27134abfb05ef9218e8d6139fe29219b2be4902b Issue 7322 - Taking address of deprecated functions isn't refused AddrExp::semantic is missing a check when e1 is a VarExp. https://github.com/D-Programming-Language/dmd/commit/d5dc77452b7f6d0c0768bf33ff3f8172fc0cc482 Merge pull request #670 from yebblies/issue7322 Issue 7322 - Taking address of deprecated functions isn't refused
Comment #3 by edmccard — 2012-07-18T17:44:07Z
(In reply to comment #2) The fix from pull #670 gets confused when there are "undeprecated" overloads; for example, here are several ways that a deprecated function can still be called through a function pointer: int foo(int a) { return 0; } deprecated int foo(float a) { return 1; } void main() { int function(float) fp1 = &foo; auto fp2 = cast(int function(float))&foo; assert(fp1(0.0) == 1); assert(fp2(0.0) == 1); } If foo(int) instead of foo(float) is deprecated, then an error is issued even though it should be possible to take the address of the undeprecated function. (I've been having similar problems trying to fix issue 144; in these situtations, I think AddrExp::semantic is too early in the compilation process for applying fixes that may be affected by overload resolution.)
Comment #4 by k.hara.pg — 2012-07-19T08:57:10Z
(In reply to comment #3) > If foo(int) instead of foo(float) is deprecated, then an error is issued even > though it should be possible to take the address of the undeprecated function. > > (I've been having similar problems trying to fix issue 144; in these > situtations, I think AddrExp::semantic is too early in the compilation process > for applying fixes that may be affected by overload resolution.) An example that accidentally rejected with current git head: deprecated int foo(float a) { return 1; } int foo(int a) { return 0; } void main() { int function(float) fp1 = &foo; // test.d(10): Error: function test.foo is deprecated <- Bad! }
Comment #5 by github-bugzilla — 2012-07-19T09:00:18Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/bdb1f13fa9124a56dda0b36697b394e890758241 Revert "Merge pull request #670 from yebblies/issue7322" This reverts commit d5dc77452b7f6d0c0768bf33ff3f8172fc0cc482, reversing changes made to 00778d310b6980ac7068398f4dac22aa4860b8d4.
Comment #6 by yebblies — 2012-07-19T09:27:42Z
The deprecation check needs to be done where the overload set is resolved, wherever that is.
Comment #7 by k.hara.pg — 2012-07-19T09:37:43Z
(In reply to comment #6) > The deprecation check needs to be done where the overload set is resolved, > wherever that is. DotVarExp and VarExp have `hasOverloads` field that means whether the overloaded symbol is really resolved or not. In these cases, CastExp::semantic and AddrExp::implicitConvTo might be better places.
Comment #8 by edmccard — 2012-07-27T20:34:11Z
Comment #9 by k.hara.pg — 2013-07-04T07:36:18Z
Comment #10 by k.hara.pg — 2015-06-01T23:36:12Z
*** Issue 14559 has been marked as a duplicate of this issue. ***
Comment #11 by robert.schadek — 2024-12-13T17:57:51Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18401 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB