[CODE HEALTH] Fix clang-tidy narrowing-conversions warnings in otlp_populate_attribute_utils#4090
Open
thc1006 wants to merge 1 commit into
Open
Conversation
b15a543 to
e9fc36b
Compare
There was a problem hiding this comment.
Pull request overview
Updates OTLP exporter code to align existing clang-tidy suppression comments with the clang-tidy v22 check name, and adjusts CI warning limits accordingly. This is a code health/CI maintenance change intended to keep the clang-tidy ratchet stable after the LLVM/clang-tidy 22 upgrade.
Changes:
- Renames four
NOLINTsuppressions inotlp_populate_attribute_utils.ccfrom the old alias tobugprone-narrowing-conversions. - Lowers
clang-tidyworkflow warning limits forall-options-abiv1-previewandall-options-abiv2-preview. - Adds a corresponding
CHANGELOG.mdentry.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| exporters/otlp/src/otlp_populate_attribute_utils.cc | Updates four narrowing-conversion NOLINT suppressions to match clang-tidy v22’s check name. |
| CHANGELOG.md | Adds an Unreleased entry for the code health change. |
| .github/workflows/clang-tidy.yaml | Lowers the warning limits to reflect the reduced warning count. |
e9fc36b to
cc4c581
Compare
| { | ||
| proto_value->set_int_value( | ||
| nostd::get<uint64_t>(value)); // NOLINT(cppcoreguidelines-narrowing-conversions) | ||
| proto_value->set_int_value(static_cast<int64_t>(nostd::get<uint64_t>(value))); |
| { | ||
| array_value->add_values()->set_int_value( | ||
| val); // NOLINT(cppcoreguidelines-narrowing-conversions) | ||
| array_value->add_values()->set_int_value(static_cast<int64_t>(val)); |
| { | ||
| array_value->add_values()->set_int_value( | ||
| val); // NOLINT(cppcoreguidelines-narrowing-conversions) | ||
| array_value->add_values()->set_int_value(static_cast<int64_t>(val)); |
cc4c581 to
2c3d074
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4090 +/- ##
==========================================
- Coverage 81.99% 81.99% -0.00%
==========================================
Files 385 385
Lines 16023 16019 -4
==========================================
- Hits 13137 13133 -4
Misses 2886 2886
🚀 New features to boost your workflow:
|
3 tasks
thc1006
added a commit
to thc1006/opentelemetry-cpp
that referenced
this pull request
May 18, 2026
Eliminate the 29 misc-unused-alias-decls warnings flagged by clang-tidy across 27 files in examples, exporters, sdk, and tests. The most common pattern was a file-scope `namespace nostd = opentelemetry::nostd;` declaration that was never referenced via the file-scope alias path (uses of `nostd::` resolved through the surrounding OPENTELEMETRY_BEGIN_NAMESPACE namespace nesting instead). No behavior change. Removed declarations were genuinely dead per clang-tidy. Where removing an alias affected sibling-line alignment (e.g. `using M = ...` next to the removed alias), clang-format auto-collapsed the alignment. Ratchet: * abiv1-preview warning_limit lowered from 418 to 389 * abiv2-preview warning_limit lowered from 424 to 395 A 30th misc-unused-alias-decls site at exporters/otlp/src/otlp_populate_attribute_utils.cc:30 is intentionally not touched in this PR to avoid conflicting with the in-flight open-telemetry#4090. It can be cleaned up in a follow-up after open-telemetry#4090 lands. Part of open-telemetry#2053 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
thc1006
added a commit
to thc1006/opentelemetry-cpp
that referenced
this pull request
May 18, 2026
Eliminate 29 misc-unused-alias-decls warnings flagged by clang-tidy v22 across 27 files in examples, exporters, sdk, and tests. The dominant pattern was a file-scope `namespace nostd = opentelemetry::nostd;` declaration never referenced via the file-scope alias path (uses of `nostd::` resolved through OPENTELEMETRY_BEGIN_NAMESPACE namespace nesting instead). Also remove 4 unused type-alias `using M = std::map<std::string, std::string>;` declarations in storage tests, observed by Copilot review. clang-tidy does not flag these (misc-unused-alias-decls targets only namespace aliases, not type aliases), but they are genuinely dead code in the same spirit and the same files this PR already touches. No behavior change. Removed declarations were genuinely unused. clang-format auto-collapsed adjacent orphan alignment whitespace where removing a line left aligned siblings. Ratchet: * abiv1-preview warning_limit lowered from 418 to 389 * abiv2-preview warning_limit lowered from 424 to 395 A 30th misc-unused-alias-decls site at exporters/otlp/src/otlp_populate_attribute_utils.cc:30 is intentionally not touched in this PR to avoid conflicting with the in-flight open-telemetry#4090. It can be cleaned up in a trivial follow-up after open-telemetry#4090 lands. Part of open-telemetry#2053 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
thc1006
added a commit
to thc1006/opentelemetry-cpp
that referenced
this pull request
May 18, 2026
Eliminate 29 misc-unused-alias-decls warnings flagged by clang-tidy v22 across 27 files in examples, exporters, sdk, and tests. The dominant pattern was a file-scope `namespace nostd = opentelemetry::nostd;` declaration never referenced via the file-scope alias path (uses of `nostd::` resolved through OPENTELEMETRY_BEGIN_NAMESPACE namespace nesting instead). Also remove 4 unused type-alias `using M = std::map<std::string, std::string>;` declarations in storage tests, observed by Copilot review. clang-tidy does not flag these (misc-unused-alias-decls targets only namespace aliases, not type aliases), but they are genuinely dead code in the same spirit and the same files this PR already touches. No behavior change. Removed declarations were genuinely unused. clang-format auto-collapsed adjacent orphan alignment whitespace where removing a line left aligned siblings. Ratchet: * abiv1-preview warning_limit lowered from 418 to 389 * abiv2-preview warning_limit lowered from 424 to 395 A 30th misc-unused-alias-decls site at exporters/otlp/src/otlp_populate_attribute_utils.cc:30 is intentionally not touched in this PR to avoid conflicting with the in-flight open-telemetry#4090. It can be cleaned up in a trivial follow-up after open-telemetry#4090 lands. Part of open-telemetry#2053 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
thc1006
added a commit
to thc1006/opentelemetry-cpp
that referenced
this pull request
May 18, 2026
Eliminate 29 misc-unused-alias-decls warnings flagged by clang-tidy v22 across 27 files in examples, exporters, sdk, and tests. The dominant pattern was a file-scope `namespace nostd = opentelemetry::nostd;` declaration never referenced via the file-scope alias path (uses of `nostd::` resolved through OPENTELEMETRY_BEGIN_NAMESPACE namespace nesting instead). Also remove 4 unused type-alias `using M = std::map<std::string, std::string>;` declarations in storage tests, observed by Copilot review. clang-tidy does not flag these (misc-unused-alias-decls targets only namespace aliases, not type aliases), but they are genuinely dead code in the same spirit and the same files this PR already touches. Also remove 9 now-unused #include directives that IWYU flagged as a consequence of the alias removals: when an alias like `namespace http_client = opentelemetry::ext::http::client;` is removed, the include that brought the namespace into scope is no longer needed. Same logic for several `opentelemetry/common/attribute_value.h` includes that supported `namespace common = opentelemetry::common;` aliases, and `<map>` after removing the unused `using M = ...` from async_metric_storage_test.cc. No behavior change. Removed declarations were genuinely unused. clang-format auto-collapsed adjacent orphan alignment whitespace where removing a line left aligned siblings. Ratchet: * abiv1-preview warning_limit lowered from 418 to 389 * abiv2-preview warning_limit lowered from 424 to 395 A 30th misc-unused-alias-decls site at exporters/otlp/src/otlp_populate_attribute_utils.cc:30 is intentionally not touched in this PR to avoid conflicting with the in-flight open-telemetry#4090. It can be cleaned up in a trivial follow-up after open-telemetry#4090 lands. Part of open-telemetry#2053 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
…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 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>
2c3d074 to
785ec9a
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.
Summary
After the clang-tidy v22 upgrade in #4066, four narrowing-conversion warnings surfaced in
exporters/otlp/src/otlp_populate_attribute_utils.cc, at the fouruint64_ttoint64_tcall sites passing values to protoset_int_value:uint64_t(PopulateAnyValue first overload)nostd::span<const uint64_t>arrayuint64_t(PopulateAnyValue second overload)std::vector<uint64_t>arrayWhy static_cast, not a NOLINT rename
An earlier attempt to fix these by renaming the existing
NOLINT(cppcoreguidelines-narrowing-conversions)to the newbugprone-alias name did not work: in clang-tidy v22 both names are registered as separate aliases, and NOLINT for one alias does not suppress reporting under the other. The warning simply flips to the other alias name. A single-name NOLINT cannot silence the diagnostic.This PR instead replaces the four implicit narrowings with explicit
static_cast<int64_t>conversions, matching the pattern established in the prior narrowing-cleanup PRs #3989, #3997, and #4013. This eliminates the alias dependency entirely and makes each narrowing explicit at the call site. No runtime behavior change — implicit narrowing under two's-complement was already producing the same bit pattern.A fifth NOLINT at line ~297 (a
uint32_ttoint64_tconversion, which is signed widening rather than narrowing) is left untouched. clang-tidy v22 emits no warning there, and removing the dead NOLINT is out of scope.Ratchet
all-options-abiv1-previewwarning_limitlowered from 418 to 414all-options-abiv2-previewwarning_limitlowered from 424 to 420Verification
Counts measured against artifacts of the most recent successful CI run on
main(workflowclang-tidy.yaml, run26018587378):Test plan
clang-tidyjob passes both abiv1-preview and abiv2-preview at the new limitsFormatjob passes (single-line static_cast expressions fit within 100 chars)OtlpPopulateAttributeUtils::PopulateAnyValue; existing tests inexporters/otlp/test/otlp_recordable_test.ccstill cover the modified branches via type-parameterized tests overuint64_tPart of #2053