[Issue 7301] RegexMatch opCast!bool not working

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 17 12:57:09 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7301



--- Comment #7 from Jerry Quinn <jlquinn at optonline.net> 2012-01-17 12:57:07 PST ---
(In reply to comment #6)
> (In reply to comment #5)
> > (In reply to comment #4)
> > > Neither int (outside the range [0,1]) nor RegexMatch implicitly convert to
> > > bool. Negating counts as an explicit cast to bool.
> > 
> opCast means explicit cast, as in cast(bool)regexMatch or !regexMatch or
> regexMatch && 2.

I think this is the crux of what we're arguing about.  To me, explicit casting
happens when you write cast(T) in the code.  When the compiler generates a cast
for you, that's implicit casting.

Is this not correct?

It seems to me that opCast is pretty useless unless the compiler can decide to
use it to convert an object for you.

> > http://www.d-programming-language.org/operatoroverloading.html#Cast claims that
> > both ! and bare references will get rewritten to opCast!bool:
> > 
> >   if (e)   =>  if (e.opCast!(bool))
> >   if (!e)  =>  if (!e.opCast!(bool))
> > 
> > That should take care of the return, no?
> 
> That only works for conditions and arguments to boolean operators. If you think
> it should also work for return values where the enclosing function is declared
> to return bool, then that is an enhancement request. It might be a reasonable
> one.

Why should it only work in those cases?  I can't find anything in the language
docs that says this.  The docs on functions say that when a type is passed in,
implicit conversion is used as one of the match possibilities.  That's opCast,
no?  So if parameter passing is using opCast for implicit conversion, the
return statement should be too.  Hence my labeling this as a bug.

> > Note that the same compile failure happens if I write:
> > 
> >   auto re = regex("test");
> >   if (match("test", re)) { ... }
> > 
> 
> Works for me.

My mistake - this case does work.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list