Skip to content

[CODE HEALTH] Replace push_back with emplace_back where applicable (#4476) - #4485

Merged
marcalff merged 4 commits into
open-telemetry:mainfrom
sunny-kumar-75:fix-4476-emplace
Aug 27, 2026
Merged

marcalff merged 4 commits into
open-telemetry:mainfrom
sunny-kumar-75:fix-4476-emplace

Conversation

@sunny-kumar-75

Copy link
Copy Markdown
Contributor

Use emplace_back instead of push_back to construct objects in-place, avoiding unnecessary temporary object creation and copy/move operations. Changes span test files, examples, exporters, and ext headers.

Fixes #4476

Changes

  • Test files: Use emplace_back for std::string, context::Context, shared_ptr, and std::thread construction
  • otlp_file_client.cc: Use emplace_back for string tokens
  • http_server.h: Use emplace_back for HttpRequestHandler construction
  • socket_tools.h: Use emplace_back() for default-constructed SocketData
  • Benchmark files: Use emplace_back for std::thread with lambda arguments

Checklist

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added (existing tests cover all affected code — no new tests needed for this refactoring)
  • Changes in public API reviewed (no public API changes)

…4476)

Use emplace_back instead of push_back to construct objects in-place, avoiding unnecessary temporary object creation and copy/move operations. Changes span test files, examples, exporters, and ext headers.
@sunny-kumar-75
sunny-kumar-75 requested a review from a team as a code owner August 26, 2026 09:52
@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: sunny-kumar-75 / name: Sunny Kumar (6b2eae2)

@codecov

codecov Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.13%. Comparing base (75e36ac) to head (6d56744).

Files with missing lines Patch % Lines
exporters/otlp/src/otlp_file_client.cc 33.34% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4485      +/-   ##
==========================================
+ Coverage   83.12%   83.13%   +0.01%     
==========================================
  Files         519      519              
  Lines       20256    20256              
==========================================
+ Hits        16835    16837       +2     
+ Misses       3421     3419       -2     
Files with missing lines Coverage Δ
...nclude/opentelemetry/ext/http/server/http_server.h 66.67% <100.00%> (ø)
...clude/opentelemetry/ext/http/server/socket_tools.h 95.68% <100.00%> (ø)
exporters/otlp/src/otlp_file_client.cc 70.38% <33.34%> (ø)

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

@marcalff marcalff changed the title Replace push_back with emplace_back where applicable (#4476) [CODE HEALTH] Replace push_back with emplace_back where applicable (#4476) Aug 26, 2026

@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 .github/workflows/clang-tidy.yam with the new warning limits (113 and 124)

See the clang-tidy reports in the job summary from CI here:
https://github.com/open-telemetry/opentelemetry-cpp/actions/runs/32955276312?pr=4485

@sunny-kumar-75
sunny-kumar-75 requested a review from dbarker August 27, 2026 04:46
@marcalff
marcalff merged commit 45f2629 into open-telemetry:main Aug 27, 2026
77 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 modernize-use-emplace warnings

3 participants