[CODE HEALTH] Fix clang-tidy narrowing-conversions warnings in sync_instruments#4013
Merged
marcalff merged 3 commits intoApr 21, 2026
Merged
Conversation
thc1006
added a commit
to thc1006/opentelemetry-cpp
that referenced
this pull request
Apr 20, 2026
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
8575386 to
3d09f19
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4013 +/- ##
=======================================
Coverage 90.34% 90.34%
=======================================
Files 230 230
Lines 7303 7303
=======================================
Hits 6597 6597
Misses 706 706
🚀 New features to boost your workflow:
|
Eliminate the last two cppcoreguidelines-narrowing-conversions warnings in the SDK. Both occur in the abiv2-only LongHistogram::Record overloads, where uint64_t values are passed to RecordLong (which expects int64_t). The cast is observably equivalent to the prior code: implicit narrowing under two's-complement already produced the same bit pattern. Add a test exercising the abiv2-only LongHistogram::Record(uint64_t) and Record(uint64_t, KeyValueIterable&) overloads, which were not covered by the existing LongHistogram test. Ratchet: * abiv1-preview warning_limit unchanged (31) * abiv2-preview warning_limit lowered from 33 to 31 Part of open-telemetry#2053 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
3d09f19 to
68f896a
Compare
marcalff
approved these changes
Apr 20, 2026
Member
marcalff
left a comment
There was a problem hiding this comment.
LGTM, thanks for the cleanup.
2 tasks
thc1006
added a commit
to thc1006/opentelemetry-cpp
that referenced
this pull request
May 18, 2026
…opulate_attribute_utils After the clang-tidy v22 upgrade in open-telemetry#4066, four narrowing-conversion warnings surfaced in otlp_populate_attribute_utils.cc at the four uint64_t to int64_t call sites passing to proto set_int_value. The original code suppressed via NOLINT(cppcoreguidelines-narrowing-conversions). In clang-tidy v22 both bugprone-narrowing-conversions and cppcoreguidelines-narrowing-conversions are registered as separate aliases, and NOLINT for one alias does not suppress the report under the other. So an alias-name-rename approach cannot silence the warnings with a single NOLINT. Replace the four NOLINT-suppressed implicit narrowings with explicit static_cast<int64_t> conversions, matching the pattern established in open-telemetry#3989, open-telemetry#3997, and open-telemetry#4013. This removes the alias dependency entirely and makes the narrowing explicit at the call site. The fifth NOLINT at line ~297 (uint32_t to int64_t) is signed widening, not narrowing; clang-tidy v22 emits no diagnostic there. Left untouched. Ratchet: * abiv1-preview warning_limit lowered from 418 to 414 * abiv2-preview warning_limit lowered from 424 to 420 Part of open-telemetry#2053 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
Open
3 tasks
thc1006
added a commit
to thc1006/opentelemetry-cpp
that referenced
this pull request
May 18, 2026
…opulate_attribute_utils After the clang-tidy v22 upgrade in open-telemetry#4066, four narrowing-conversion warnings surfaced in otlp_populate_attribute_utils.cc at the four uint64_t to int64_t call sites passing to proto set_int_value. The original code suppressed via NOLINT(cppcoreguidelines-narrowing-conversions). In clang-tidy v22 both bugprone-narrowing-conversions and cppcoreguidelines-narrowing-conversions are registered as separate aliases, and NOLINT for one alias does not suppress the report under the other. So an alias-name-rename approach cannot silence the warnings with a single NOLINT. Replace the four NOLINT-suppressed implicit narrowings with explicit static_cast<int64_t> conversions, matching the pattern established in open-telemetry#3989, open-telemetry#3997, and open-telemetry#4013. This removes the alias dependency entirely and makes the narrowing explicit at the call site. The fifth NOLINT at line ~297 (uint32_t to int64_t) is signed widening, not narrowing; clang-tidy v22 emits no diagnostic there. Left untouched. Ratchet: * abiv1-preview warning_limit lowered from 418 to 414 * abiv2-preview warning_limit lowered from 424 to 420 Part of open-telemetry#2053 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
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.
Summary
Eliminates the last two
cppcoreguidelines-narrowing-conversionswarnings remaining in the project. Both occur in the abiv2-onlyLongHistogram::Recordoverloads insdk/src/metrics/sync_instruments.cc(lines 463 and 475), where auint64_t valueparameter is passed directly toSyncWritableMetricStorage::RecordLong, whose signature expectsint64_t. Wrapping the argument instatic_cast<int64_t>makes the narrowing explicit and silences the diagnostic.The cast is observably equivalent to the prior code. Implicit narrowing under two's-complement was already producing the same bit pattern; this PR only makes the conversion explicit at the call site. There is no behavior change.
After this change, the project's narrowing-conversions warning count is 0 under both
all-options-abiv1-previewandall-options-abiv2-preview, completing the narrowing-conversions cleanup tracked under #2053.Ratchet
all-options-abiv1-previewwarning_limitunchanged at 31 (no abiv1 narrowing warnings in this file)all-options-abiv2-previewwarning_limitlowered from 33 to 31 (the two warnings being fixed are abiv2-only)Verification
Counts measured against artifacts of the most recent successful CI run on
main(run24674777807, head699664b7):Test coverage
The existing
TEST(SyncInstruments, LongHistogram)insdk/test/metrics/sync_instruments_test.ccexercised only the non-abiv2Record(int64_t, ...)overloads. The abiv2-onlyRecord(uint64_t)andRecord(uint64_t, KeyValueIterable&)overloads being modified in this PR were not previously covered. This PR adds calls to both overloads, guarded by#if OPENTELEMETRY_ABI_VERSION_NO >= 2, so the abiv2 build now exercises the modified code paths.Test plan
clang-tidyjob passes both abiv1-preview and abiv2-preview at the new limitRecord(uint64_t)overloads via the new test additionsLongHistogram::RecordPart of #2053