Skip to content

[CODE HEALTH] Move func_http_main classes into anonymous namespace#4128

Merged
marcalff merged 1 commit into
open-telemetry:mainfrom
thc1006:codehealth/func-http-internal-linkage
Jun 6, 2026
Merged

[CODE HEALTH] Move func_http_main classes into anonymous namespace#4128
marcalff merged 1 commit into
open-telemetry:mainfrom
thc1006:codehealth/func-http-internal-linkage

Conversation

@thc1006

@thc1006 thc1006 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Wraps the 3 file-scope class/struct declarations in
functional/otlp/func_http_main.cc within an anonymous namespace,
clearing the misc-use-internal-linkage warnings.

6th PR of the misc-use-internal-linkage campaign (#4115, #4116, #4121,
#4122, #4124 already merged). First PR in the campaign touching the
functional/ tree.

Changes

  • functional/otlp/func_http_main.cc: insert namespace { after the
    command-line opt_* variables and } // namespace after the
    test_case struct closing brace. Wrap covers TestResult (line 62),
    TestLogHandler (line 145), and test_case (line 333).
  • .github/workflows/clang-tidy.yaml: abiv1 352 -> 349 (-3),
    abiv2 356 -> 353 (-3).
  • CHANGELOG.md: one bullet under [Unreleased].

Why the wrap ends before line 339 (NOT before main())

The static int test_*() forward declarations (lines 339-440) are
matched by definitions in the lower half of the file (lines 1484-1882,
after main()). Wrapping declarations alone would produce
(anonymous namespace)::test_* symbols that do not link against the
file-scope static int test_*() definitions.

Verified locally: a wrap extending to line 453 (just before main())
produced 12+ undefined reference linker errors. The shortened wrap
ending at line 337 builds cleanly.

main() keeps external linkage. The static const test_case all_tests[] table and list_test_cases / run_test_case helpers
remain at file scope with their existing static linkage.

Test plan

  • Local build of func_otlp_http: 121/121 ninja steps
    (-DWITH_OTLP_HTTP=ON -DWITH_OTLP_GRPC=OFF)
  • func_otlp_http --help smoke test prints usage
  • clang-format --dry-run --Werror clean on the modified file
  • DCO signed off

Part of #2053

@thc1006 thc1006 requested a review from a team as a code owner June 5, 2026 23:22
Wraps the 3 file-scope class and struct declarations in
functional/otlp/func_http_main.cc within an anonymous namespace to
give them internal linkage and clear the misc-use-internal-linkage
warnings clang-tidy reports on this file.

The wrap covers TestResult (line 62), TestLogHandler (line 145), and
test_case (line 333). It deliberately ends BEFORE the static int
test_*() forward declarations at line 339+.

This boundary matters: the test_*() declarations are matched by
definitions in the lower half of the file (lines 1484-1882, after
main()). Wrapping the declarations alone would create
(anonymous namespace)::test_* symbols that fail to link against the
file-scope static test_*() definitions. Verified locally: extending
the wrap to line 453 produced 12+ undefined reference linker errors;
the shortened wrap ending at line 337 builds cleanly (121/121 ninja
steps for func_otlp_http target with WITH_OTLP_HTTP=ON).

main() and all test_*() infrastructure (declarations, the
all_tests[] table, list_test_cases, run_test_case, and definitions)
remain at file scope with their existing static linkage.

Ratchet:
* abiv1-preview warning_limit lowered from 352 to 349
* abiv2-preview warning_limit lowered from 356 to 353

Part of open-telemetry#2053

Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
@thc1006 thc1006 force-pushed the codehealth/func-http-internal-linkage branch from ac756ae to 2cc3267 Compare June 5, 2026 23:22
@marcalff marcalff merged commit 5791b30 into open-telemetry:main Jun 6, 2026
70 checks passed
@codecov

codecov Bot commented Jun 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.94%. Comparing base (5cdcc38) to head (2cc3267).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4128      +/-   ##
==========================================
- Coverage   81.95%   81.94%   -0.01%     
==========================================
  Files         385      385              
  Lines       16067    16067              
==========================================
- Hits        13166    13164       -2     
- Misses       2901     2903       +2     

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@thc1006 thc1006 deleted the codehealth/func-http-internal-linkage branch June 6, 2026 01:05
thc1006 added a commit to thc1006/opentelemetry-cpp that referenced this pull request Jun 6, 2026
Wraps the 3 file-scope class and struct declarations in
functional/otlp/func_grpc_main.cc within an anonymous namespace to
give them internal linkage and clear the misc-use-internal-linkage
warnings clang-tidy reports on this file.

The wrap covers TestResult (line 63), TestLogHandler (line 128), and
test_case (line 316). It deliberately ends BEFORE the static int
test_*() forward declarations at line 322+.

This boundary follows the same pattern as open-telemetry#4128 (func_http_main):
the test_*() declarations are matched by definitions in the lower
half of the file (after main()). Wrapping the declarations alone
would create (anonymous namespace)::test_* symbols that fail to
link against the file-scope static test_*() definitions. Local
verification: build of func_otlp_grpc target with
WITH_OTLP_HTTP=ON + WITH_OTLP_GRPC=ON succeeded 122/122 ninja steps;
--help smoke test prints usage as expected.

main() and all test_*() infrastructure (declarations, the
all_tests[] table, list_test_cases, run_test_case, and definitions)
remain at file scope with their existing static linkage.

Ratchet:
* abiv1-preview warning_limit lowered from 349 to 346
* abiv2-preview warning_limit lowered from 353 to 350

Part of open-telemetry#2053

Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
marcalff pushed a commit that referenced this pull request Jun 6, 2026
…4129)

Wraps the 3 file-scope class and struct declarations in
functional/otlp/func_grpc_main.cc within an anonymous namespace to
give them internal linkage and clear the misc-use-internal-linkage
warnings clang-tidy reports on this file.

The wrap covers TestResult (line 63), TestLogHandler (line 128), and
test_case (line 316). It deliberately ends BEFORE the static int
test_*() forward declarations at line 322+.

This boundary follows the same pattern as #4128 (func_http_main):
the test_*() declarations are matched by definitions in the lower
half of the file (after main()). Wrapping the declarations alone
would create (anonymous namespace)::test_* symbols that fail to
link against the file-scope static test_*() definitions. Local
verification: build of func_otlp_grpc target with
WITH_OTLP_HTTP=ON + WITH_OTLP_GRPC=ON succeeded 122/122 ninja steps;
--help smoke test prints usage as expected.

main() and all test_*() infrastructure (declarations, the
all_tests[] table, list_test_cases, run_test_case, and definitions)
remain at file scope with their existing static linkage.

Ratchet:
* abiv1-preview warning_limit lowered from 349 to 346
* abiv2-preview warning_limit lowered from 353 to 350

Part of #2053

Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants