Skip to content

[CODE HEALTH] fix clang-tidy cppcoreguidelines-pro-type-const-cast warnings - #4482

Open
Anish701 wants to merge 5 commits into
open-telemetry:mainfrom
Anish701:fix-const-cast-4477
Open

[CODE HEALTH] fix clang-tidy cppcoreguidelines-pro-type-const-cast warnings#4482
Anish701 wants to merge 5 commits into
open-telemetry:mainfrom
Anish701:fix-const-cast-4477

Conversation

@Anish701

@Anish701 Anish701 commented Aug 26, 2026

Copy link
Copy Markdown

Fixes #4477

Changes

Resolves all cppcoreguidelines-pro-type-const-cast warnings by eliminating const_cast usage through proper typing.

Note: The methods MultiObserverResult::ForInstrument and MultiObserverResult::HasInstrument have their parameters changed from const ObservableInstrument* to ObservableInstrument*. The previous const qualifier was misleading because there was a const_cast on the pointer. Also, all existing callers already pass non-const pointers. This is not a breaking change to the API. All unit tests pass successfully.

  • examples/http: Accept const T& in HttpTextMapCarrier constructor, removing the need to const_cast request headers.
  • ext/http/client/curl: Change SetCurlPtrOption to accept const void*, and use mutable std::vector copies for blob data instead of const_cast from string data.
  • ext/test/w3c_tracecontext_http_test_server: Copy headers by value instead of const_casting a reference.
  • sdk/common/circular_buffer.h: Make PeekImpl() a const method, eliminating the const_cast<CircularBuffer*>(this) in Peek().
  • sdk/metrics/multi_observer_result: Change ForInstrumentDouble, ForInstrumentInt64, and HasInstrument to accept ObservableInstrument* (non-const) since the internal map key is non-const. This is an API signature change because the previous const parameter was misleading as mentioned in the note above.
  • CHANGELOG.md updated for non-trivial changes - N/A this is a trivial code health change
  • Unit tests have been added - N/A
  • Changes in public API reviewed - yes mentioned in description

Signed-off-by: Anish701 <anish2sinha@gmail.com>
@Anish701
Anish701 requested a review from a team as a code owner August 26, 2026 04:51
@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 26, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: Anish701 / name: Anish Sinha (4297c36)
  • ✅ login: Anish701 / name: Anish701 (d2890d8)

@Anish701 Anish701 changed the title [CODE HEALTH] clang-tidy cppcoreguidelines-pro-type-const-cast warnings [CODE HEALTH] fix clang-tidy cppcoreguidelines-pro-type-const-cast warnings Aug 26, 2026
@codecov

codecov Bot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 36.84211% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.11%. Comparing base (45f2629) to head (e36cf5b).

Files with missing lines Patch % Lines
ext/src/http/client/curl/http_operation_curl.cc 7.70% 12 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4482      +/-   ##
==========================================
- Coverage   83.12%   83.11%   -0.00%     
==========================================
  Files         519      519              
  Lines       20256    20254       -2     
==========================================
- Hits        16835    16832       -3     
- Misses       3421     3422       +1     
Files with missing lines Coverage Δ
...lude/opentelemetry/metrics/multi_observer_result.h 100.00% <ø> (ø)
...lemetry/ext/http/client/curl/http_operation_curl.h 90.91% <100.00%> (-0.39%) ⬇️
...include/opentelemetry/sdk/common/circular_buffer.h 100.00% <100.00%> (ø)
sdk/src/metrics/multi_observer_result.cc 92.31% <100.00%> (-0.41%) ⬇️
ext/src/http/client/curl/http_operation_curl.cc 60.30% <7.70%> (-0.29%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CODE HEALTH] clang-tidy cppcoreguidelines-pro-type-const-cast warnings

1 participant