[SERVER-1371] BSONObjBuilder does not handle uint64_t correctly (overloaded append() are ambiguous) Created: 07/Jul/10  Updated: 27/Sep/11  Resolved: 07/Jul/10

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: Mark Sung Assignee: Eliot Horowitz (Inactive)
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu Lucid 64bit, GCC 4.3.4/4.4.3


Backwards Compatibility: Major Change
Operating System: Linux
Participants:

 Description   

The following code does not compile due to ambiguous BSONObjBuilder::append() overload

code:
uint64_t orz = 10;
BSONObj o = BSON("test" << orz);

gcc compile error messages:

/usr/include/mongo/client/../db/jsobj.h:1924: error: call of overloaded 'append(const char*&, long unsigned int&)' is ambiguous
/usr/include/mongo/client/../db/jsobj.h:1208: note: candidates are: void mongo::BSONObjBuilder::append(const char*, mongo::BSONObj) <near match>
/usr/include/mongo/client/../db/jsobj.h:1214: note: void mongo::BSONObjBuilder::append(const std::string&, mongo::BSONObj) <near match>
/usr/include/mongo/client/../db/jsobj.h:1253: note: void mongo::BSONObjBuilder::append(const char*, bool)
/usr/include/mongo/client/../db/jsobj.h:1260: note: void mongo::BSONObjBuilder::append(const char*, int)
/usr/include/mongo/client/../db/jsobj.h:1266: note: void mongo::BSONObjBuilder::append(const std::string&, int)
/usr/include/mongo/client/../db/jsobj.h:1271: note: void mongo::BSONObjBuilder::append(const char*, unsigned int)
/usr/include/mongo/client/../db/jsobj.h:1274: note: void mongo::BSONObjBuilder::append(const char*, long long int)
/usr/include/mongo/client/../db/jsobj.h:1281: note: void mongo::BSONObjBuilder::append(const std::string&, long long int)
/usr/include/mongo/client/../db/jsobj.h:1322: note: mongo::BSONObjBuilder& mongo::BSONObjBuilder::append(const char*, double)
/usr/include/mongo/client/../db/jsobj.h:1370: note: void mongo::BSONObjBuilder::append(const char*, mongo::Date_t)
/usr/include/mongo/client/../db/jsobj.h:1398: note: mongo::BSONObjBuilder& mongo::BSONObjBuilder::append(const char*, const char*) <near match>
/usr/include/mongo/client/../db/jsobj.h:1406: note: void mongo::BSONObjBuilder::append(const char*, std::string) <near match>

Apparently the problem is that BSONObjBuilder::append() does not overload specifically for "unsigned long long" type so for uint64_t it's possible to match all types, leading to ambiguous overload.

This bug is in all release, including the trunk version.



 Comments   
Comment by Liang Sun [ 27/Sep/11 ]

I think you should have implemented a method with an unsigned 64 bit integer type, as what the long unsigned integer type is depends on the c++ compiler.

Comment by Eliot Horowitz (Inactive) [ 07/Jul/10 ]

there isn't an unsigned 64 bit integer type, so this message is correct.
you should cast to what you need

Generated at Thu Feb 08 02:56:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.