[CODE HEALTH] Fix clang-tidy narrowing-conversions warnings in tests#3987
Open
mateenali66 wants to merge 3 commits intoopen-telemetry:mainfrom
Open
[CODE HEALTH] Fix clang-tidy narrowing-conversions warnings in tests#3987mateenali66 wants to merge 3 commits intoopen-telemetry:mainfrom
mateenali66 wants to merge 3 commits intoopen-telemetry:mainfrom
Conversation
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>
Signed-off-by: Mateen Anjum <mateenali66@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3987 +/- ##
=======================================
Coverage 90.18% 90.18%
=======================================
Files 230 230
Lines 7299 7299
=======================================
Hits 6582 6582
Misses 717 717 🚀 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
sdk/test/metrics/aggregation_test.cc
Outdated
| @@ -416,8 +416,8 @@ TEST(Aggregation, Base2ExponentialHistogramAggregationMerge) | |||
| const int expected_scale = | |||
| aggr_point.scale_ < default_point.scale_ ? aggr_point.scale_ : default_point.scale_; | |||
| const int expected_max_buckets = aggr_point.max_buckets_ < default_point.max_buckets_ | |||
Member
There was a problem hiding this comment.
nit - better to fix the type of the test variables to match those compared
Author
There was a problem hiding this comment.
addressed in the latest commit. changed expected_max_buckets to size_t and updated the test_merge lambda parameter to match, so no cast needed.
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>
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