[SERVER-29474] Fix ODR violations from anonymous namespace in header files Created: 06/Jun/17  Updated: 30/Oct/23  Resolved: 23/Aug/19

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

Type: Bug Priority: Major - P3
Reporter: ADAM Martin (Inactive) Assignee: ADAM Martin (Inactive)
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-29480 Fix anonymous namespace ODR violation... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Dev Tools 2019-08-12, Dev Tools 2019-08-26
Participants:

 Comments   
Comment by Githook User [ 23/Aug/19 ]

Author:

{'name': 'ADAM David Alan Martin', 'email': 'adam.martin@10gen.com', 'username': 'adamlsd'}

Message: SERVER-29474 Fix ODR violations from anonymous namespace in headers.

A few headers are special; they aren't really multiply included
headers. Those headers still hold their anonymous namespace
blocks.
Branch: master
https://github.com/mongodb/mongo/commit/07b1fef352d3a534513a28b333fe3b63c4aab551

Comment by Andrew Morrow (Inactive) [ 22/Jun/19 ]

We find the following hits in the community repo:

find src/mongo -name "*.h" | xargs grep 'namespace {$' | sort
src/mongo/db/catalog/private/record_store_validate_adaptor.h:namespace {
src/mongo/db/storage/record_store_test_docwriter.h:namespace {
src/mongo/platform/decimal128_bson_test.h:namespace {
src/mongo/util/dns_query_android-impl.h:namespace {
src/mongo/util/dns_query_posix-impl.h:namespace {
src/mongo/util/dns_query_windows-impl.h:namespace {
src/mongo/util/log.h:namespace {

We find no hits in the enterprise repo for that search. However, none of the community hits are real issues. Going file by file:

  • The record_store_validate_adaptor.h header is included in more than one place, but only has a `using` within the unnamed namespace, which is meaningless and can be de-wrapped.
  • The record_store_test_docwriter.h header is only included from .cpp files.
  • The decimal128_bson_test.h file is only used in tests and only included from .cpp files.
  • All three dns_query... header files are only included from .cpp files and have whitelisting to ensure they are not misused.
  • The util/log.h header is similarly only permitted to be included from .cpp files and has an appropriate whitelist.

In the interest of avoiding cargo-culting of this dangerous pattern into more places, we should fix up the first three.

Generated at Thu Feb 08 04:20:59 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.