Skip to content
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

Fix C4459: Rename a function parameter profiler_manager to avoid hiding the global declaration. #1839

Merged
merged 6 commits into from
Aug 19, 2024

Conversation

fsb4000
Copy link
Contributor

@fsb4000 fsb4000 commented Aug 18, 2024

Hello.
Thank you for your library!
I tried to upgrade from 1.8.5 to 1.9.0 and I faced with an error:

D:\a\_work\1\s\benchmarks\google-benchmark\src\benchmark_runner.cc(129,35): error C2220: the following warning is treated as an error
                 ProfilerManager* profiler_manager) {
                                  ^
D:\a\_work\1\s\benchmarks\google-benchmark\src\benchmark_runner.cc(129,35): warning C4459: declaration of 'profiler_manager' hides global declaration
D:\a\_work\1\s\benchmarks\google-benchmark\src\benchmark_runner.cc(65,18): note: see declaration of 'benchmark::internal::profiler_manager'
ProfilerManager* profiler_manager = nullptr;
                 ^

Would you mind a slight renaming to solve the issue?
Feel free to suggest a better name...

Copy link

google-cla bot commented Aug 18, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@LebedevRI
Copy link
Collaborator

Looks like MSVC CI jobs are not in warnings-as-error mode,
so if you care about that compiler, i'd suggest to also
adjust the CI infra here so new warnings don't go unnoticed,
and make the build green. Does that sound like too much to ask for?

@fsb4000
Copy link
Contributor Author

fsb4000 commented Aug 19, 2024

Sure, I will modify the CI.

@fsb4000 fsb4000 marked this pull request as draft August 19, 2024 01:44
@LebedevRI
Copy link
Collaborator

Thank you!

@fsb4000 fsb4000 marked this pull request as ready for review August 19, 2024 02:02
@fsb4000
Copy link
Contributor Author

fsb4000 commented Aug 19, 2024

I restored my changes and I added only -WX flag.
I did:

cmake -E make_directory "build"
cmake -E chdir "build" cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release ../
cmake --build "build" --config Release

and I got:
изображение
After that I added my renaming and tried the build again. It passed.
Let's look if the CI passes.

@LebedevRI
Copy link
Collaborator

(#1838 suggests it should not)

@fsb4000
Copy link
Contributor Author

fsb4000 commented Aug 19, 2024

Oh, yes. I forgot that I locally removed BENCHMARK_INTERNAL_CACHELINE_ALIGNED because it was intentionally and not a bug, I would change the MS STL CI to not warn on it.

@fsb4000
Copy link
Contributor Author

fsb4000 commented Aug 19, 2024

LebedevRI
LebedevRI previously approved these changes Aug 19, 2024
Copy link
Collaborator

@LebedevRI LebedevRI left a comment

Choose a reason for hiding this comment

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

Looks like a non-intrusive improvement to me.

@LebedevRI LebedevRI self-requested a review August 19, 2024 02:30
@LebedevRI
Copy link
Collaborator

Hm, akctually, looking at include/benchmark/benchmark.h, there's precedent for more targeted warning hiding:

#if defined(_MSC_VER)
#pragma warning(push)
// C4251: <symbol> needs to have dll-interface to be used by clients of class
#pragma warning(disable : 4251)
#endif // _MSC_VER_

I looked for that before, but didn't find it on the first try...
I think we might want to do the same here.

@fsb4000
Copy link
Contributor Author

fsb4000 commented Aug 19, 2024

Sure.

And about code analysis.

I got

C:\Dev\STL\benchmarks\google-benchmark\src\timers.cc(282,1): error C2220: следующее предупреждение рассматривается как ошибка [C:\Dev\STL\benchmarks\google-benchmark\build\src\benchmark.vcxproj]
C:\Dev\STL\benchmarks\google-benchmark\src\timers.cc(280): warning C6053: Предыдущий вызов "strncpy" может привести к тому, что строка "tz_offset" не будет завершаться нулем.: Lines: 211, 212, 213, 214, 216, 217, 218, 219, 231, 233, 236
, 243, 245, 266, 271, 274, 276, 278, 280 [C:\Dev\STL\benchmarks\google-benchmark\build\src\benchmark.vcxproj]
  Создание кода...
  gtest-all.cc
  gmock-all.cc
  gmock_main.cc
  Выполнение Code Analysis для C/C++...
C:\Dev\STL\benchmarks\google-benchmark\build\third_party\googletest\src\googletest\include\gtest/internal/gtest-internal.h(627,1): error C2220: следующее предупреждение рассматривается как ошибка [C:\Dev\STL\benchmarks\google-benchmark\
build\third_party\googletest\build\googlemock\gmock_main.vcxproj]
C:\Dev\STL\benchmarks\google-benchmark\build\third_party\googletest\src\googletest\include\gtest\internal\gtest-internal.h(625): warning C6326: Возможное сравнение константы с другой константой. [C:\Dev\STL\benchmarks\google-benchmark\b
uild\third_party\googletest\build\googlemock\gmock_main.vcxproj]
C:\Dev\STL\benchmarks\google-benchmark\build\third_party\googletest\src\googletest\include\gtest/internal/gtest-internal.h(627,1): error C2220: следующее предупреждение рассматривается как ошибка [C:\Dev\STL\benchmarks\google-benchmark\
build\third_party\googletest\build\googlemock\gmock_main.vcxproj]
C:\Dev\STL\benchmarks\google-benchmark\build\third_party\googletest\src\googletest\include\gtest\internal\gtest-internal.h(625): warning C6326: Возможное сравнение константы с другой константой. [C:\Dev\STL\benchmarks\google-benchmark\b
uild\third_party\googletest\build\googlemock\gmock_main.vcxproj]
C:\Dev\STL\benchmarks\google-benchmark\build\third_party\googletest\src\googletest\include\gtest/internal/gtest-internal.h(627,1): error C2220: следующее предупреждение рассматривается как ошибка [C:\Dev\STL\benchmarks\google-benchmark\
build\third_party\googletest\build\googlemock\gmock_main.vcxproj]
C:\Dev\STL\benchmarks\google-benchmark\build\third_party\googletest\src\googletest\include\gtest\internal\gtest-internal.h(625): warning C6326: Возможное сравнение константы с другой константой. [C:\Dev\STL\benchmarks\google-benchmark\b
uild\third_party\googletest\build\googlemock\gmock_main.vcxproj]
  Создание кода...

When I enabled it by adding add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/analyze:autolog->") to CMakeLists.txt
So maybe we will add MSVS code analyzer in another PR, won't we?

@LebedevRI
Copy link
Collaborator

When I enabled it by adding add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/analyze:autolog->") to CMakeLists.txt So maybe we will add MSVS code analyzer in another PR, won't we?

Absolutely. In fact, i was only asking about the warnings part, not the static analysis, but thank you for checking!

@LebedevRI LebedevRI merged commit c19cfee into google:main Aug 19, 2024
80 checks passed
@LebedevRI
Copy link
Collaborator

@fsb4000 thank you!

@fsb4000
Copy link
Contributor Author

fsb4000 commented Aug 19, 2024

@LebedevRI My pleasure!

@fsb4000 fsb4000 deleted the fixC4459 branch August 19, 2024 05:29
@LebedevRI LebedevRI mentioned this pull request Sep 6, 2024
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.

2 participants