Guh! – buh!! – wuh!!!

bool CInclusionCriteriaMatcher::NestedTypesMatch() {

    CInheritance inheritanceTree;


    if (SUCCEEDED(inheritanceTree.Initialize(this->type, true/*fInherit*/))) {

        while (inheritanceTree.MoveNext()) {

            if (NestedTypesMatch(inheritanceTree.Current())) {

                return S_OK;





    return false;


Spot the bug?

In beautiful C++ land it’s perfectl fine to implicitly convert an HRESULT to a bool.  Of course, S_OK gets converted to “false” so this function ends up doing… you guessed it… ABSOLUTELY NOTHING.

Sigh.  Anyways, the score currently stands at:

Stupid languages that allow bizarre narrowing conversions without warning you: -129

Great girls who program with you late at night and keep you productive even with crap like above: +infinity

Comments (5)

  1. Stuart Dootson says:

    Hmmmm – not sure I entirely agree with your C++ criticism, Cyrus….

    S_OK is #defined as 0 – an integer literal, so the text the compiler sees (after pre-processing, remember) is ‘return 0’. What are the valid values of a bool? 0 or 1(false or true). Therefore the compiler can statically determine that there is no narrowing, which is why you get no warning.

    Use some integer literal other than 0 or 1 and you will get told. For example – in the code below, I get a warning for ‘blah = 2;’.

    void Flibble()


    bool blah = S_OK;

    blah = 1;

    blah = 2;


  2. Me says:

    Stupid languages that allow to hide your code with UGLYMACRO : how much ?

  3. Stuart: 0 is an integer literal. so it narrowed that integer to a boolean without telling me. That’s bad.

  4. Mikey says:

    But isnt a boolean also an int? It may not need to take up the space of an int but it does for effeciency

  5. Nothing to say, interisting point of view.


    John from <a href=’‘>monaco hotels</a> ( ***