Skip to content

[CODE HEALTH] Qualify C library calls with std:: after modernize-deprecated-headers - #4356

Open
om7057 wants to merge 3 commits into
open-telemetry:mainfrom
om7057:codehealth/std-qualify-clib-calls
Open

[CODE HEALTH] Qualify C library calls with std:: after modernize-deprecated-headers#4356
om7057 wants to merge 3 commits into
open-telemetry:mainfrom
om7057:codehealth/std-qualify-clib-calls

Conversation

@om7057

@om7057 om7057 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #4354

Changes

Follow-up to #4349. Swapping deprecated C headers for their C++ equivalents left the underlying library calls unqualified (memcpy, strcmp, isspace, strtod, snprintf, strftime, etc.), relying on most implementations also exposing these names in the global namespace, which the standard does not guarantee.

Adds std:: to call sites for the functions covered by <cstring>, <cctype>, <cstdlib>, <cstdio>, and <ctime>, plus the FILE and tm types, across api, sdk, exporters, ext, examples, and functional. Also adds a couple of #includes that were missing and relied on transitive inclusion.

Left untouched, per review feedback on #4349:

  • Vendored code (api/include/opentelemetry/nostd/internal/absl, exporters/etw/include/opentelemetry/exporters/etw/TraceLoggingDynamic.h)
  • Call sites already qualified with :: (explicit global scope), since that looked like a deliberate choice rather than an oversight
  • Platform-specific functions with no std:: form (gmtime_r/gmtime_s, strtok_s/strtok_r)

Test plan

  • Full local build (cmake --build .) with BUILD_TESTING, WITH_EXAMPLES, WITH_FUNC_TESTS, WITH_OTLP_FILE, WITH_OTLP_HTTP, WITH_CONFIGURATION, and WITH_EXAMPLES_HTTP enabled, 0 errors, 0 warnings.
  • ctest on both configs, 796/796 and 1233/1237 passed (the 4 failures were ext.http.curl timing tests that are flaky under parallel load in this environment; all pass at -j1).

Follow-up to open-telemetry#4349: swapping deprecated C headers for their C++
equivalents left the underlying calls unqualified (memcpy, strcmp,
isspace, strtod, snprintf, strftime, etc.), relying on most
implementations also exposing these names in the global namespace,
which isn't guaranteed by the standard. Adds std:: to call sites for
the functions covered by <cstring>, <cctype>, <cstdlib>, <cstdio>,
and <ctime>, plus the FILE and tm types, across api, sdk, exporters,
ext, examples, and functional. Leaves already ::-qualified call
sites, vendored code (absl, TraceLoggingDynamic.h), and
platform-specific functions (gmtime_r/gmtime_s, strtok_s/strtok_r)
untouched.

Fixes open-telemetry#4354
@om7057
om7057 requested a review from a team as a code owner August 4, 2026 19:04
@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.44444% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.86%. Comparing base (9c0cee5) to head (78cad85).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
exporters/otlp/src/otlp_file_client.cc 75.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4356      +/-   ##
==========================================
+ Coverage   80.86%   80.86%   +0.01%     
==========================================
  Files         450      450              
  Lines       19216    19230      +14     
==========================================
+ Hits        15537    15549      +12     
- Misses       3679     3681       +2     
Files with missing lines Coverage Δ
api/include/opentelemetry/common/kv_properties.h 98.87% <100.00%> (ø)
api/include/opentelemetry/common/string_util.h 87.50% <100.00%> (ø)
api/include/opentelemetry/trace/span_id.h 100.00% <100.00%> (ø)
api/include/opentelemetry/trace/trace_id.h 100.00% <100.00%> (ø)
api/include/opentelemetry/trace/trace_state.h 94.12% <ø> (ø)
...nclude/opentelemetry/ext/http/server/http_server.h 66.67% <100.00%> (ø)
...clude/opentelemetry/ext/http/server/socket_tools.h 95.68% <100.00%> (ø)
ext/src/http/client/curl/http_operation_curl.cc 58.60% <100.00%> (ø)
sdk/src/common/random.cc 96.00% <100.00%> (ø)
sdk/src/configuration/document_node.cc 72.90% <100.00%> (ø)
... and 2 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

instrument_metadata_validator.cc only calls isalpha/isalnum in the
!OPENTELEMETRY_HAVE_WORKING_REGEX fallback path, so an unconditional
<cctype> include is unused whenever the regex path is taken, which is
what IWYU's zero-warning CI jobs flagged.

@marcalff marcalff left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

[CODE HEALTH] Qualify C library calls with std:: after modernize-deprecated-headers

2 participants