jeudi 21 mars 2019

Global function recognition failing

When having a simple qtest which compares 2 different objects for a user-defined struct:

Test a, b = {1};
QCOMPARE(a, b);

Why is there a difference between:

(1)

static char* toString(const Test &)
{
    using QTest::toString;
    return toString("Test");
}

And

(2)

namespace {

char* toString(const Test &)
{
    using QTest::toString;
    return toString("Test");
}

} // unnamed namespace

The first one does call the function when comparing the objects, the second one does not!

As mentioned in this conclusion, there should be no difference except anonymous namespaces allow you to define translation-unit-local type. Well, here it looks like it's the opposite.

Aucun commentaire:

Enregistrer un commentaire