[CODE HEALTH] Fix clang-tidy narrowing conversions in baggage#3989
Merged
dbarker merged 2 commits intoopen-telemetry:mainfrom Apr 13, 2026
Merged
[CODE HEALTH] Fix clang-tidy narrowing conversions in baggage#3989dbarker merged 2 commits intoopen-telemetry:mainfrom
dbarker merged 2 commits intoopen-telemetry:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Addresses new cppcoreguidelines-narrowing-conversions clang-tidy warnings in the Baggage URL encode/decode helpers and adjusts the clang-tidy CI threshold accordingly, keeping the project’s warning budget ratcheting downward.
Changes:
- Add explicit
static_cast<char>(...)at three previously-implicitint -> charconversion sites inBaggage::UrlEncode/Baggage::UrlDecode. - Lower
warning_limitin the clang-tidy GitHub Actions workflow for the two preview matrix entries to match the reduced warning count. - Add an Unreleased changelog entry for the code health change.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
api/include/opentelemetry/baggage/baggage.h |
Makes narrowing conversions explicit to satisfy clang-tidy’s narrowing-conversions check. |
.github/workflows/clang-tidy.yaml |
Updates warning thresholds to reflect the reduced clang-tidy warning count. |
CHANGELOG.md |
Records the code health change in the Unreleased section. |
Wrap three int->char conversions inside Baggage::UrlEncode and Baggage::UrlDecode with explicit static_cast<char>(...) so that cppcoreguidelines-narrowing-conversions stops firing on api/include/opentelemetry/baggage/baggage.h:238,239,270 under clang-tidy 20. The change is purely a source-level cast: c >> 4 and c & 15 are already bounded to [0, 15] by the surrounding mask/shift, and the bitwise OR of two nibbles in UrlDecode fits in a single byte. The existing baggage_test cases cover both UrlEncode and UrlDecode round-trips and remain green. Decrement the clang-tidy warning_limit by 3 for both all-options-abiv1-preview and all-options-abiv2-preview matrix entries to ratchet the limit down to the new measured count. Resolves open-telemetry#3980. Part of open-telemetry#2053. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
1e4b011 to
6a3e3c0
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3989 +/- ##
==========================================
- Coverage 90.18% 90.17% -0.01%
==========================================
Files 230 230
Lines 7299 7299
==========================================
- Hits 6582 6581 -1
- Misses 717 718 +1
🚀 New features to boost your workflow:
|
dbarker
approved these changes
Apr 13, 2026
Member
dbarker
left a comment
There was a problem hiding this comment.
Looks good. Thanks for the contribution!
malkia
added a commit
to malkia/opentelemetry-cpp
that referenced
this pull request
Apr 14, 2026
[CODE HEALTH] Fix clang-tidy narrowing conversions in baggage (open-telemetry#3989)
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 #3980
Contributes to #2053
Changes
int -> charconversions insideBaggage::UrlEncodeand
Baggage::UrlDecodewith explicitstatic_cast<char>(...)so thatcppcoreguidelines-narrowing-conversionsstops firing under clang-tidy 20.clang-tidy.yamlwarning_limitby 3 for bothall-options-abiv1-previewandall-options-abiv2-previewmatrix entriesto ratchet the limit down to the new measured count.
The arithmetic is unchanged:
c >> 4andc & 15are already bounded to[0, 15]by the existing shift/mask, and the bitwise OR of twofrom_hexnibbles in
UrlDecodefits in a single byte. PR #1353 already added the samestatic_cast<char>inside thefrom_hexlambda body back in 2022; thischange just finishes the job at the call sites that clang-tidy 20 newly
flags.
Fixes the following warnings:
opentelemetry-cpp/api/include/opentelemetry/baggage/baggage.h (3 warnings)
cppcoreguidelines-narrowing-conversionscppcoreguidelines-narrowing-conversionscppcoreguidelines-narrowing-conversionsFor significant contributions please make sure you have completed the following items:
CHANGELOG.mdupdated for non-trivial changes