Bug 8767 – expression of type bool() does not have a boolean value?
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-05T20:13:00Z
Last change time
2014-05-06T19:11:40Z
Assigned to
nobody
Creator
blooh_
Comments
Comment #0 by blooh_ — 2012-10-05T20:13:57Z
Please consider the code below:
// ------------------------------
enum Storage : int
{
dynamic = 0
}
enum StorageOrder : int
{
columnMajor = 0,
rowMajor = 1
}
alias StorageOrder.columnMajor defaultStorageOrder;
class Array( T_scalar, T_args ... )
{
alias ArrayTraits!( T_scalar, T_args ) traits;
}
class ArrayTraits( T_scalar, T_args ... )
{
static if ( hasFlag!( Flags.storageOrder ) )
alias T_args[0 .. $ - 1] shapeTuple;
else
alias T_args shapeTuple;
static immutable StorageOrder storageOrder = hasFlag!( Flags.storageOrder ) ?
T_args[$ - 1] : defaultStorageOrder;
static int getFlags()
{
int flags = 0;
if ( is( typeof( T_args[$ - 1] ) == StorageOrder ) )
flags |= Flags.storageOrder;
return flags;
}
static bool hasFlag( Flags flag )()
{
return (getFlags() & flag) != 0;
}
enum Flags : int
{
dynamic = 1 << 0,
storageOrder = 1 << 1
}
}
void main()
{
auto array1d = new Array!( float, 3 );
}
// ------------------------------
It triggers a compilation error, which is:
/home/c189/c597.d(23): Error: expression hasFlag!(cast(Flags)2) of type bool() does not have a boolean value
It can be fixed in the code by changing the erroring line to:
static if ( hasFlag!( Flags.storageOrder ) == true )
but I don't really understand why the comparison to true must be explicitely written since the hasFlag() method returns a bool value?
Comment #1 by dmitry.olsh — 2012-10-06T01:50:00Z
> It can be fixed in the code by changing the erroring line to:
> static if ( hasFlag!( Flags.storageOrder ) == true )
> but I don't really understand why the comparison to true must be explicitely
> written since the hasFlag() method returns a bool value?
I'd expect hasFlag!(Flags.storageOrder)() to call this function. And without parens it can be treated as function pointer. That being said 0-arg functions usually gets called without parens implicitly.
Comment #2 by k.hara.pg — 2012-10-06T02:04:52Z
I think this is a dup of bug 7174.
Comment #3 by k.hara.pg — 2012-10-07T12:09:43Z
OK. Now bug 7174 is fixed, then the test code works with no error.
*** This issue has been marked as a duplicate of issue 7174 ***
Comment #4 by github-bugzilla — 2014-05-06T18:40:44Z