If func is a function (not a function pointer) with zero arguments, it works correctly (I think). But if it is a function with >0 arguments, then it complains that it cannot evaluate it. Curiously, it generates the correct result, as evidenced by pragma(msg) below, before giving the error. -------------- double func0() { return 0; } int func2(int a, int b) { return 2; } void main() { static assert(typeof(func0).stringof=="(double())()"); // OK pragma(msg, typeof(func2).stringof); // bug.d(8): Error: expected 2 arguments, not 0 // (int(int a, int b))() static assert(typeof(func2).stringof=="(int(int a, int b))()"); }
d-bugmail@puremagic.com wrote: > http://d.puremagic.com/issues/show_bug.cgi?id=1373 > > Summary: typeof(func).stringof fails when func has parameters. > Product: D > Version: 1.019 > Platform: PC > OS/Version: Windows > Status: NEW > Severity: normal > Priority: P2 > Component: DMD > AssignedTo: bugzilla@digitalmars.com > ReportedBy: clugdbug@yahoo.com.au > > > If func is a function (not a function pointer) with zero arguments, it works > correctly (I think). But if it is a function with >0 arguments, then it > complains that it cannot evaluate it. > > Curiously, it generates the correct result, as evidenced by pragma(msg) below, > before giving the error. > > -------------- > double func0() { return 0; } > int func2(int a, int b) { return 2; } > > void main() > { > static assert(typeof(func0).stringof=="(double())()"); // OK > pragma(msg, typeof(func2).stringof); > // bug.d(8): Error: expected 2 arguments, not 0 > // (int(int a, int b))() > static assert(typeof(func2).stringof=="(int(int a, int b))()"); > } > > I think a related issue is void func(int) {} const text = func.stringof; which doesn't compile under 2.003, error message: "func_stringof.func(int) does not match parameter types ()". However, it works if the int parameter is removed.
Please don't blindly quote the entire message when replying. It's bad enough on any newsgroup, and when it clutters up Bugzilla, it's even worse. This issue is puzzling me. Surely typeof(func0) should be double, since as an expression, func0 is equivalent to func0(). And typeof(func2) probably shouldn't compile.
(In reply to comment #2) > Please don't blindly quote the entire message when replying. It's bad enough > on any newsgroup, and when it clutters up Bugzilla, it's even worse. > > This issue is puzzling me. Surely typeof(func0) should be double, since as an > expression, func0 is equivalent to func0(). And typeof(func2) probably > shouldn't compile. Function types _are_ wierd. And not well documented. What is func2 ? It's a symbol of "function type". The only thing you do with it it takes its address. Since in the spec, it's allowable in & UnaryExpression, it must be an expression, but I can't see it listed there. Definitely related to issue #1341.
This issue bugged me with DMD 2.043 on Mac. I noticed something peculiar which is demonstrated by this test case: ----- void foo(int i) { } enum string FOO_TYPE = typeof(foo).stringof; pragma(msg, "Type of foo is: " ~ FOO_TYPE); ----- Compiling that will print: ----- stringof_error.d(2): Error: expected 1 function arguments, not 0 Type of foo is: (void(int i))() ----- So actually, the .stringof is correctly evaluated, but still some unnecessary check for function arguments makes the compiler generate an error.
https://github.com/D-Programming-Language/dmd/commit/28702b21e143807205f6798b000a0c05bb22d5e2 https://github.com/D-Programming-Language/dmd/commit/23bef66be596ab4541fe26a5433f8cdbd92fc4ac
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル