[CDRIVER-1387] BSON_EXTRA_ALIGN 0 does not compile with MSVC Created: 15/Jul/16  Updated: 10/Aug/16  Resolved: 18/Jul/16

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

Type: Bug Priority: Minor - P4
Reporter: Shane Harvey Assignee: Shane Harvey
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible

 Description   

If BSON_EXTRA_ALIGN is 0 the BSON_ALIGNED_BEGIN macro defined here is invalid.

MSVC does not allow mathematical expressions in align:

__declspec( align( # ) ) declarator

...

# is the alignment value. Valid entries are integer powers of two from 1 to 8192 (bytes), such as 2, 4, 8, 16, 32, or 64.

https://msdn.microsoft.com/en-us/library/83ythb65.aspx

The cmake file always sets BSON_EXTRA_ALIGN to 1 so this was never noticed.
https://github.com/mongodb/libbson/blob/33851d13/CMakeLists.txt#L70-L92



 Comments   
Comment by Githook User [ 18/Jul/16 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@emptysquare.net'}

Message: Merge pull request #170 from ShaneHarvey/master

CDRIVER-1387 Fix MSVC syntax error in align
Branch: master
https://github.com/mongodb/libbson/commit/6d0e8b2edc8f5c62740bd0795f6434f7ea8e079d

Comment by Githook User [ 18/Jul/16 ]

Author:

{u'username': u'ShaneHarvey', u'name': u'Shane Harvey', u'email': u'shane.harvey@mongodb.com'}

Message: CDRIVER-1387 Fix MSVC syntax error in align
Branch: master
https://github.com/mongodb/libbson/commit/46b7549de61559d76b437a59a2014d6dc5026012

Comment by Shane Harvey [ 15/Jul/16 ]

It's not even possible to do align((8)) because of the extra parentheses. So

// syntax error
define BSON_ALIGNED_BEGIN(_N) __declspec (align ((_N) > BSON_ALIGN_OF_PTR ? BSON_ALIGN_OF_PTR : (_N) ))
// syntax error
define BSON_ALIGNED_BEGIN(_N) __declspec (align ((_N)))
// correct
define BSON_ALIGNED_BEGIN(_N) __declspec (align (_N))

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