[CDRIVER-2271] BSON_STATIC_ASSERT can trigger "error: redefinition of typedef" in clang Created: 10/Sep/17  Updated: 28/Oct/23  Resolved: 12/Jan/18

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

Type: Improvement Priority: Major - P3
Reporter: A. Jesse Jiryu Davis Assignee: A. Jesse Jiryu Davis
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CDRIVER-2450 Altering BSON_STATIC_ASSERT_JOIN2 mac... Closed

 Description   

The BSON_ASSERT macro uses typedef tricks to force a compilation error if the static invariant it asserts is false. Unfortunately the symbols it typedefs are named only using the line number on which BSON_ASSERT is used. E.g. if there is a BSON_ASSERT on line 112, then a symbol static_assert_test_112 is involved in checking the invariant. If BSON_ASSERT is used in two files on the same line number in each, a pedantic compiler errors, "error: redefinition of typedef 'static_assert_test_112'".

See for example:

https://evergreen.mongodb.com/task_log_raw/mongo_c_driver_clang35_debug_compile_nosasl_nossl_patch_294976a086ce1a1d7c8dc904d8ba2503ae7e648e_59b413ede3c3311323000252_17_09_09_16_16_45/0?type=T#L907

To solve, make a new macro BSON_STATIC_ASSERT2 that allows a custom string prefix:

BSON_STATIC_ASSERT2 (sizeof_counter_slots,
                     sizeof (mongoc_counter_slots_t) == 64);



 Comments   
Comment by Githook User [ 10/Jan/18 ]

Author:

{'email': 'ppisar@redhat.com', 'name': 'Petr Písař', 'username': 'ppisar'}

Message: CDRIVER-2460 fix BSON_STATIC_ASSERT definition

The macro definition was mistakenly changed in 1.9.0 (CDRIVER-2271) and partly
reverted (CDRIVER-2450). This change completely reverts the macro to its 1.8.0
definition.

Signed-off-by: Petr Písař <ppisar@redhat.com>
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/35b0a890a50714b74d7793073d4d9e6693f70ad8

Comment by Githook User [ 15/Oct/17 ]

Author:

{'email': 'jesse@mongodb.com', 'name': 'A. Jesse Jiryu Davis', 'username': 'ajdavis'}

Message: CDRIVER-2271 avoid duplicate BSON_STATIC_ASSERTs
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/164fc951b00526343e9290f5d143bdf53f93b080

Comment by Githook User [ 15/Oct/17 ]

Author:

{'email': 'jesse@mongodb.com', 'name': 'A. Jesse Jiryu Davis', 'username': 'ajdavis'}

Message: CDRIVER-2271 avoid duplicate BSON_STATIC_ASSERTs
Branch: master
https://github.com/mongodb/libbson/commit/4e27abb58de93736a3cff082300448184d2a3715

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