digitalmars.D.learn - is(T == const) for function types
- mist (2/2) Dec 25 2012 http://dpaste.dzfl.pl/0cda8d0f
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (21/23) Dec 25 2012 For convenience to others, here is your code:
- bearophile (4/5) Dec 25 2012 That difference smells of compiler bug :-)
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (10/15) Dec 25 2012 Hmmm. I think the compiler is right. That const that is applied "at the
- bearophile (5/8) Dec 25 2012 You seem right. The positional syntax of those tags tricks me
- mist (21/39) Dec 26 2012 Yes, looks like I was not checking
On 12/25/2012 12:59 PM, mist wrote:http://dpaste.dzfl.pl/0cda8d0f bug or feature?For convenience to others, here is your code: struct Test { void delegate() const deleg; } void main() { static assert( is(typeof(Test.deleg) == const) ); } I don't know the answer but this works: struct Test { alias void delegate() Deleg; const Deleg deleg; } void main() { static assert( is(typeof(Test.deleg) == const) ); } Ali
Dec 25 2012
Ali Çehreli:I don't know the answer but this works:That difference smells of compiler bug :-) Bye, bearophile
Dec 25 2012
On 12/25/2012 04:13 PM, bearophile wrote:Ali Çehreli:Hmmm. I think the compiler is right. That const that is applied "at the end" in that syntax is I think allowed only for member functions. Otherwise these two work as well: // These work: const(void delegate()) deleg; const void delegate() deleg; // This is a compilation error: void delegate() const deleg; AliI don't know the answer but this works:That difference smells of compiler bug :-) Bye, bearophile
Dec 25 2012
Ali Çehreli:Hmmm. I think the compiler is right. That const that is applied "at the end" in that syntax is I think allowed only for member functions. Otherwise these two work as well:You seem right. The positional syntax of those tags tricks me sometimes still. Bye, bearophile
Dec 25 2012
On Wednesday, 26 December 2012 at 00:47:28 UTC, Ali Çehreli wrote:On 12/25/2012 04:13 PM, bearophile wrote:Yes, looks like I was not checking http://dlang.org/declaration.html good enough and assumed C-like model where "Type const var" is as legal as "const Type var". There is a surprising revelation provided by Kenji in context of member variable delegates: struct Test { void delegate() const deleg; } void main() { static if (is(typeof(Test.deleg) F == delegate)) { pragma(msg, "Sure, delegate"); static assert( is(F == const) ); } } "Delegate type qualifier cannot test directly. You should extract function type from it, then test const." (c) Kenji Copying it here from github for any possible lucky googlers :)Ali Çehreli:Hmmm. I think the compiler is right. That const that is applied "at the end" in that syntax is I think allowed only for member functions. Otherwise these two work as well: // These work: const(void delegate()) deleg; const void delegate() deleg; // This is a compilation error: void delegate() const deleg; AliI don't know the answer but this works:That difference smells of compiler bug :-) Bye, bearophilee
Dec 26 2012