[CODE HEALTH] Fix clang-tidy narrowing-conversions warnings in tests#3987
Merged
dbarker merged 5 commits intoopen-telemetry:mainfrom Apr 14, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3987 +/- ##
==========================================
- 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 10, 2026
Member
dbarker
left a comment
There was a problem hiding this comment.
Thanks for the cleanup! Just some minor optional nitpicks
mateenali66
added a commit
to mateenali66/opentelemetry-cpp
that referenced
this pull request
Apr 10, 2026
Addresses review nit on open-telemetry#3987. max_buckets_ is size_t on the aggregation point data, so declaring expected_max_buckets as size_t and updating the test_merge lambda parameter to match eliminates the narrowing at the source rather than casting it away. Signed-off-by: Mateen Anjum <mateenali66@gmail.com>
mateenali66
added a commit
to mateenali66/opentelemetry-cpp
that referenced
this pull request
Apr 13, 2026
Addresses review nit on open-telemetry#3987. max_buckets_ is size_t on the aggregation point data, so declaring expected_max_buckets as size_t and updating the test_merge lambda parameter to match eliminates the narrowing at the source rather than casting it away. Signed-off-by: Mateen Anjum <mateenali66@gmail.com>
c82fa2b to
820cb95
Compare
marcalff
requested changes
Apr 13, 2026
Member
marcalff
left a comment
There was a problem hiding this comment.
LGTM, see additional fixes in otlp_metrics_serialization.cc
mateenali66
added a commit
to mateenali66/opentelemetry-cpp
that referenced
this pull request
Apr 13, 2026
per @marcalff's review on open-telemetry#3987. the three loops in Counter, Histogram and ObservableGauge were `for (size_t i = 0; i < 1; i++)` so they only ran once, but the test data in each Create*AggregationData helper pushes two PointDataAttributes and the body references both via `i == 0 ? v1 : v2`. silent partial coverage from day one. switched the index to `int` (silences the narrowing without a cast) and the bound to 2, so the second data point is actually verified. Refs open-telemetry#3978 Signed-off-by: Mateen Anjum <mateenali66@gmail.com>
Apply static_cast at the narrowing site in three test files: - otlp_metrics_serialization_test.cc: cast loop index when calling protobuf data_points(int) accessors (3 sites). - aggregation_test.cc: cast size_t max_buckets_ on ternary branches where the lvalue is declared int (2 sites). - metric_test_stress.cc: cast hardware_concurrency() result and the uint64_t bucket counts/totals used for int64_t accumulation (3 sites). Decrement clang-tidy warning limits by 8 to match the removed unique warnings. Fixes open-telemetry#3978 Signed-off-by: Mateen Anjum <mateenali66@gmail.com>
Addresses review nit on open-telemetry#3987. max_buckets_ is size_t on the aggregation point data, so declaring expected_max_buckets as size_t and updating the test_merge lambda parameter to match eliminates the narrowing at the source rather than casting it away. Signed-off-by: Mateen Anjum <mateenali66@gmail.com>
iwyu flagged the missing include after switching expected_max_buckets from int to size_t. Signed-off-by: Mateen Anjum <mateenali66@gmail.com>
per @marcalff's review on open-telemetry#3987. the three loops in Counter, Histogram and ObservableGauge were `for (size_t i = 0; i < 1; i++)` so they only ran once, but the test data in each Create*AggregationData helper pushes two PointDataAttributes and the body references both via `i == 0 ? v1 : v2`. silent partial coverage from day one. switched the index to `int` (silences the narrowing without a cast) and the bound to 2, so the second data point is actually verified. Refs open-telemetry#3978 Signed-off-by: Mateen Anjum <mateenali66@gmail.com>
after switching the three loop indices from size_t to int in d2d507b, the file no longer uses size_t and iwyu flagged the include as unused. Signed-off-by: Mateen Anjum <mateenali66@gmail.com>
96d0912 to
944c328
Compare
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 #3978
applied
static_castat the narrowing point in three test files:exporters/otlp/test/otlp_metrics_serialization_test.cc(3 sites) -- cast thesize_tloop index when calling protobufdata_points(int)accessors.sdk/test/metrics/aggregation_test.cc(2 sites) -- castsize_t max_buckets_in the ternary branches where the result is assigned toint. kept the lvalue type as-is becausetest_mergelambda takesint expected_max_bucketsand the values here are small test constants.sdk/test/metrics/metric_test_stress.cc(3 sites) -- casthardware_concurrency()(unsigned) and the uint64_t bucket counts/totals when accumulating intoint64_t.also decremented clang-tidy warning limits by 8.
note: #3985 (misc-use-internal-linkage) is also open against the same workflow file. whichever merges second will need a trivial rebase of the warning_limit numbers.
keeping as draft until clang-tidy CI confirms the new limits.
Changes
cppcoreguidelines-narrowing-conversionswarnings in tests.For significant contributions please make sure you have completed the following items:
CHANGELOG.mdupdated for non-trivial changes