www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8767] New: expression of type bool() does not have a boolean value?

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8767

           Summary: expression of type bool() does not have a boolean
                    value?
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: blooh_ hotmail.com


--- Comment #0 from Christopher Crouzet <blooh_ hotmail.com> 2012-10-05
20:13:57 PDT ---
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?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 05 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8767


Dmitry Olshansky <dmitry.olsh gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmitry.olsh gmail.com


--- Comment #1 from Dmitry Olshansky <dmitry.olsh gmail.com> 2012-10-06
01:50:00 PDT ---
 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 06 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8767



--- Comment #2 from Kenji Hara <k.hara.pg gmail.com> 2012-10-06 02:04:52 PDT ---
I think this is a dup of bug 7174.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 06 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8767


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2012-10-07 12:09:43 PDT ---
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 ***

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