Skip to content

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

Merged
dbarker merged 13 commits into
open-telemetry:mainfrom
Anish701:fix-const-cast-4477
Sep 1, 2026
Merged

[CODE HEALTH] fix clang-tidy cppcoreguidelines-pro-type-const-cast warnings#4482
dbarker merged 13 commits into
open-telemetry:mainfrom
Anish701:fix-const-cast-4477

Conversation

@Anish701

@Anish701 Anish701 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #4477

Changes

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

  • 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 silence const_cast warning for 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().
  • 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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.24%. Comparing base (8b8c871) to head (5b8cf88).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4482      +/-   ##
==========================================
- Coverage   83.25%   83.24%   -0.01%     
==========================================
  Files         521      521              
  Lines       20381    20379       -2     
==========================================
- Hits        16966    16962       -4     
- Misses       3415     3417       +2     
Files with missing lines Coverage Δ
...lemetry/ext/http/client/curl/http_operation_curl.h 90.91% <100.00%> (-0.39%) ⬇️
ext/src/http/client/curl/http_operation_curl.cc 60.60% <100.00%> (ø)
...include/opentelemetry/sdk/common/circular_buffer.h 100.00% <100.00%> (ø)

... 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.

@marcalff

Copy link
Copy Markdown
Member

@Anish701

Thanks for the cleanup patch.

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.

I don't think this is the proper fix, and it is a breaking change to the API: what if an existing application invokes opentelemetry with a const pointer today ?

Please avoid changing this area, in favor of #4499 which is a different fix.

Comment thread ext/src/http/client/curl/http_operation_curl.cc Outdated

@marcalff marcalff left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch.

Please revert changes related to metrics instruments, to be fixed separately.

Please revert changes related to CURL blob parameters, and silence the warning instead.

Everything else looks ok.

@Anish701

Anish701 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the patch.

Please revert changes related to metrics instruments, to be fixed separately.

Please revert changes related to CURL blob parameters, and silence the warning instead.

Everything else looks ok.

@marcalff Thanks for reviewing! I reverted the metrics related changes. I also reverted the changes to the CURL blob params and silenced the warnings with // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast).

Please let me know if any other changes are needed. Thanks!

@Anish701
Anish701 requested a review from marcalff August 29, 2026 20:20

@marcalff marcalff left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the cleanup.

@dbarker dbarker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes. Please update the warning limits in the CI workflow to subtract the 10 fixed const-cast warnings.
See .github/workflows/clang-tidy.yaml#L20

@Anish701

Anish701 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the fixes. Please update the warning limits in the CI workflow to subtract the 10 fixed const-cast warnings. See .github/workflows/clang-tidy.yaml#L20

@dbarker Sounds good. I subtracted 10 from both abiv1 and abiv2 warning limits

Signed-off-by: Anish701 <anish2sinha@gmail.com>
Signed-off-by: Anish701 <anish2sinha@gmail.com>
@Anish701
Anish701 requested a review from dbarker August 31, 2026 22:30
@dbarker
dbarker enabled auto-merge (squash) September 1, 2026 01:54
@dbarker
dbarker merged commit adc5c8a into open-telemetry:main Sep 1, 2026
75 of 76 checks passed
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

3 participants