Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-2271

BSON_STATIC_ASSERT can trigger "error: redefinition of typedef" in clang

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.9.0
    • Affects Version/s: None
    • Component/s: libbson
    • None

      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);
      

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: