Windows and "error C2872: 'byte' : ambiguous symbol"

460 views
Skip to first unread message

Jeffrey Walton

unread,
Jul 23, 2017, 12:32:19 PM7/23/17
to Crypto++ Users
Hi Everyone,

Reference https://github.com/weidai11/cryptopp/issues/447.

We are (were) catching a compile problem after moving to CryptoPP::byte. The problem is manifested in test.cpp. 'main' must not be in a namespace, so the source file has a 'using namespace CryptoPP'.

The problem is, Microsoft Window Kits put a byte in the global namespace, and its causing "error C2872: 'byte' : ambiguous symbol". We triaged the issue for the moment at https://github.com/weidai11/cryptopp/commit/00e133745663f2. The 00e13374 commit surgically applies 'using CryptoPP::byte', but it feels like a hack due to the source of the problem. Its not a multiple inheritance problem; rather, its a global namespace pollution problem.

My question is, is there a best practice around main and scoping?

Should we create a second, 'scoped_main':

    // no namespace
    int main(int argc, char* argv[])
    {
        return CryptoPP::Test::scoped_main(argc, argv);
    }

    NAMESPACE_BEGIN(CryptoPP)
    NAMESPACE_BEGIN(Test)
    int scoped_main(int argc, char* argv[])
    {
        // What 'main' used to be
        ...
    }
    NAMESPACE_END
    NAMESPACE_END

Or is adding CryptoPP:: and  CryptoPP::Test:: to everything our only other option?

Or maybe something else?

Jeff

Jeffrey Walton

unread,
Jul 23, 2017, 4:29:16 PM7/23/17
to Crypto++ Users

My question is, is there a best practice around main and scoping?

Should we create a second, 'scoped_main':

    // no namespace
    int main(int argc, char* argv[])
    {
        return CryptoPP::Test::scoped_main(argc, argv);
    }

    NAMESPACE_BEGIN(CryptoPP)
    NAMESPACE_BEGIN(Test)
    int scoped_main(int argc, char* argv[])
    {
        // What 'main' used to be
        ...
    }
    NAMESPACE_END
    NAMESPACE_END

This change was checked in at https://github.com/weidai11/cryptopp/commit/34c4c9f1bd6aa. It looks fairly clean and it tested well back to 2005.

If there are concerns or objections then please voice them. We can pivot on this issue to make sure things "just work" for users.

Jeff
Reply all
Reply to author
Forward
0 new messages