[CODE HEALTH] Enable clang-tidy modernize-deprecated-headers and fix violations - #4349
Merged
marcalff merged 6 commits intoAug 4, 2026
Merged
Conversation
Replace deprecated C headers (stdint.h, stddef.h, stdlib.h, string.h, stdio.h, ctype.h, limits.h, assert.h) with their C++ equivalents across api, sdk, exporters, ext, examples, opentracing-shim, resource_detectors, test_common, and functional tests. Also fix the IWYU mapping file, which was recommending the deprecated <time.h>/<stdio.h> headers instead of <ctime>/<cstdio>. Fixes open-telemetry#4348
The previous commit converted deprecated C headers to their C++ equivalents but didn't re-sort the resulting #include blocks, which clang-format's CI check flagged.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4349 +/- ##
=======================================
Coverage 80.86% 80.86%
=======================================
Files 450 450
Lines 19216 19216
=======================================
Hits 15537 15537
Misses 3679 3679
🚀 New features to boost your workflow:
|
The initial pass only matched unindented #include directives and missed headers included inside #if/#else branches (e.g. "# include <assert.h>"), which is why clang-tidy's CI check still flagged 9 extra modernize-deprecated-headers warnings. Also drops two includes that became duplicates once the guarded branch matched an already-unconditional include of the same C++ header.
dbarker
reviewed
Aug 4, 2026
dbarker
left a comment
Member
There was a problem hiding this comment.
Thanks for the cleanup! Please see feedback below.
api/include/opentelemetry/nostd/internal/absl and exporters/etw/include/opentelemetry/exporters/etw/TraceLoggingDynamic.h are vendored third-party sources excluded from clang-tidy, per review feedback from dbarker.
Contributor
Author
|
@dbarker Thanks for the review!
Please go through it once, and suggest if any feedback. |
dbarker
approved these changes
Aug 4, 2026
dbarker
left a comment
Member
There was a problem hiding this comment.
Thanks for the changes. Approved pending clean CI checks
…cated-headers # Conflicts: # CHANGELOG.md
om7057
added a commit
to om7057/opentelemetry-cpp
that referenced
this pull request
Aug 4, 2026
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
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4348
Changes
Enables the
modernize-deprecated-headersclang-tidy check, which was disabled in.clang-tidy, and replaces deprecated C headers with their C++ equivalents (stdint.h->cstdint,stddef.h->cstddef,stdlib.h->cstdlib,string.h->cstring,stdio.h->cstdio,ctype.h->cctype,limits.h->climits,assert.h->cassert) acrossapi,sdk,exporters,ext,examples,opentracing-shim,resource_detectors,test_common, andfunctional.As noted in the issue, IWYU was still recommending the deprecated headers, so
.iwyu.impis updated first to mapstruct tm/struct FILEusages to<ctime>/<cstdio>instead of<time.h>/<stdio.h>.Two now-duplicate includes that this change surfaced were also removed, in
api/test/core/timestamp_test.ccandexporters/elasticsearch/src/es_log_recordable.cc.CHANGELOG.mdupdated for non-trivial changes