Skip to content

Clang tidy fixes for Common++ #1884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open

Clang tidy fixes for Common++ #1884

wants to merge 3 commits into from

Conversation

egecetin
Copy link
Collaborator

@egecetin egecetin commented Jul 21, 2025

Because of the slow transition and fast changes in Common++ new warnings are generated by clang-tidy in Common++. This PR fixes new issues.

Part of #1675

@egecetin egecetin requested a review from seladb as a code owner July 21, 2025 12:27
@egecetin egecetin changed the base branch from master to dev July 21, 2025 12:27
@egecetin egecetin closed this Jul 21, 2025
@egecetin egecetin reopened this Jul 21, 2025
@egecetin egecetin mentioned this pull request Jan 12, 2025
6 tasks
Copy link
Collaborator

@Dimi1010 Dimi1010 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

codecov bot commented Jul 21, 2025

Codecov Report

Attention: Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.

Project coverage is 82.85%. Comparing base (a667b2a) to head (3323554).

Files with missing lines Patch % Lines
Common++/header/Logger.h 60.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##              dev    #1884    +/-   ##
========================================
  Coverage   82.84%   82.85%            
========================================
  Files         291      291            
  Lines       51565    51567     +2     
  Branches    11386    11433    +47     
========================================
+ Hits        42721    42724     +3     
+ Misses       8021     7681   -340     
- Partials      823     1162   +339     
Flag Coverage Δ
alpine320 74.60% <100.00%> (+<0.01%) ⬆️
fedora42 74.72% <100.00%> (-0.01%) ⬇️
macos-13 81.07% <84.61%> (+<0.01%) ⬆️
macos-14 81.07% <84.61%> (+<0.01%) ⬆️
macos-15 81.07% <84.61%> (+<0.01%) ⬆️
mingw32 69.90% <83.33%> (+<0.01%) ⬆️
mingw64 69.89% <83.33%> (+<0.01%) ⬆️
npcap 84.80% <90.00%> (+<0.01%) ⬆️
rhel94 74.45% <100.00%> (+<0.01%) ⬆️
ubuntu2004 58.75% <100.00%> (-0.01%) ⬇️
ubuntu2004-zstd 58.88% <100.00%> (+<0.01%) ⬆️
ubuntu2204 74.38% <83.33%> (-0.03%) ⬇️
ubuntu2204-icpx 60.82% <76.92%> (+0.04%) ⬆️
ubuntu2404 74.60% <100.00%> (-0.03%) ⬇️
ubuntu2404-arm64 74.59% <100.00%> (-0.03%) ⬇️
unittest 82.85% <86.66%> (+<0.01%) ⬆️
windows-2022 84.78% <90.00%> (+<0.01%) ⬆️
windows-2025 84.84% <90.00%> (+<0.01%) ⬆️
winpcap 84.94% <90.00%> (+<0.01%) ⬆️
xdp 51.30% <50.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

std::cerr << std::left << "[" << std::setw(5) << Logger::logLevelAsString(logLevel) << ": " << std::setw(45)
<< sstream.str() << "] " << logMessage << std::endl;
<< sstream.str() << "] " << logMessage << '\n';
Copy link
Owner

Choose a reason for hiding this comment

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

We always use std::endl, not sure why \n is better, but maybe we should stay consistent and always use std::endl

Copy link
Collaborator

@Dimi1010 Dimi1010 Jul 22, 2025

Choose a reason for hiding this comment

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

Because '\n' does not flush the stream buffer. std::endl flushes it every time it is encountered.
For std::cerr that doesn't do much as that stream is unbuffered, but it slows down std::cout a lot if many flushes are done unnecessarily, so it is generally more performant to use '\n'

Copy link
Collaborator Author

@egecetin egecetin Jul 22, 2025

Choose a reason for hiding this comment

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

It is a performance warning from clang-tidy. I'm not sure it impacts heavily. std::endl forces a flush but \n doesn't so it might optimize the performance of stream output slightly

Copy link
Owner

Choose a reason for hiding this comment

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

Oh I didn't know that. But for logs, don't we want to flush the buffer to make sure the log is written?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually it will flush but after some time, just not immediately so it can write multiple lines at once.

Copy link
Collaborator

@Dimi1010 Dimi1010 Jul 24, 2025

Choose a reason for hiding this comment

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

Doesn't #1639 only change the std::endl in the logger? If so, that is the same function as now. The change probably got lost when I refactored the logger.

I do think that the std::endls sprinkled in examples (mainly the help strings) need to be changed to '\n' tho.

Copy link
Collaborator Author

@egecetin egecetin Jul 24, 2025

Choose a reason for hiding this comment

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

Yes you are right, all of them were Logger or TablePrinter. But my question is should I suppress the warning completely from all files in clang-tidy or just very simple cases like this?

In examples there are some cases just multiline strings are printed with std::endl in printUsage() or EXIT_WITH_ERROR(). For printUsage I think it should be definitely \n but what should be done for error macros? One thing in my mind use std::endl for just error strings and in last line of complex multiline strings to ensure it is flushed in last line. But it will require many inline suppressions

Copy link
Collaborator

Choose a reason for hiding this comment

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

In examples there are some cases just multiline strings are printed with std::endl in printUsage() or EXIT_WITH_ERROR(). For printUsage I think it should be definitely \n but what should be done for error macros? One thing in my mind use std::endl for just error strings and in last line of complex multiline strings to ensure it is flushed in last line. But it will require many inline suppressions

I think using std::endl at the end of a conceptual message is a good solution.

Copy link
Owner

Choose a reason for hiding this comment

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

Maybe it's better to just suppress this error and fix whatever we think needs fixing?

Copy link
Collaborator Author

@egecetin egecetin Jul 24, 2025

Choose a reason for hiding this comment

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

@seladb Ok agreed I'll add global suppression for it. We can discuss it for Examples more precisely (which should keep or replaced) in its PR. Anyway, I already reverted in this PR, so it is ready to merge if there is no anything different than this

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.

3 participants