[CDRIVER-1544] libbson headers cannot be consumed from C++ due to direct use of _Decimal128 Created: 14/Sep/16  Updated: 19/Oct/16  Resolved: 20/Sep/16

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: 1.5.0
Fix Version/s: 1.5.0

Type: Bug Priority: Critical - P2
Reporter: Andrew Morrow (Inactive) Assignee: Hannes Magnusson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CXX-1033 Re-enable C driver Decimal support Closed
Related
related to CDRIVER-1176 CMake: Add _Decimal128 type check Closed

 Description   

C++ doesn't offer a _Decimal128 type. The libbson 1.5.0-rc0 headers directly make use of this type, which means that the headers cannot be consumed by C++.



 Comments   
Comment by Hannes Magnusson [ 20/Sep/16 ]

No idea why the commit doesn't show up here. But here it is: https://github.com/mongodb/libbson/commit/4d3351c40e486f042403e9e677d8450fc4ed353e

Comment by Hannes Magnusson [ 14/Sep/16 ]

We should probably just remove these functions.
They are causing more troubles then they are worth.

Our bson_decimal_t emulates BID, and can be casted to the native _Decimal128 type if it is BID encoded.

They aren't really all that benefitial. If your _Decimal128 type is BID encoded, then you can do the cast yourself.
If your _Decimal128 is DPD encoded, then these functions won't be defined and there is nothing we can currently do for you.

I suppose in the future we should add bson_decimal128_to_dpd and bson_decimal128_to_bid instead.

Comment by Andrew Morrow (Inactive) [ 14/Sep/16 ]

This is actually worse than we originally thought. It should be legal to compile the C driver with GCC (in which case the configure check will determine that _Decimal128 is available), but consume the headers for that built version of the driver with clang (also in C mode), in which case, _Decimal128 is perhaps not available. Or, for that matter, an older GCC than offers _Decimal128. I think that the conversion functions need to default invisible and opt in by a consumer preprocessor definition, like LIBBSON_ENABLE__DECIMAL128_UTILITIES, which will expose those functions, iff the driver was built with Decimal support. Basically, you can't emit these functions on the basis of the configure check.

Comment by Mira Carey [ 14/Sep/16 ]

The smart thing here is probably just to exclude the inline conversion functions ifdef __cplusplus

C++ will want the non-standard std::decimal::decimal128, which is a class wrapped around a float _attribute_((mode(TD))). So there isn't a one to one correspondence. There's the same underlying scalar type (and the C++ class can be constructed from the scalar), but I'm not sure it's worth the trouble for you.

Generated at Wed Feb 07 21:12:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.