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

fmt local scope uint conflicts with OpenCV's globally scoped uint #2809

Closed
diablodale opened this issue Mar 13, 2022 · 6 comments
Closed

fmt local scope uint conflicts with OpenCV's globally scoped uint #2809

diablodale opened this issue Mar 13, 2022 · 6 comments
Labels

Comments

@diablodale
Copy link

Unfortunately, OpenCV has a globally scoped uint type. It causes a conflict with the locally scoped uint used by fmt in 5 places.
I request fmt tweak this local typename to avoid the conflict. In my experience, OpenCV will not change.

Setup

  • fmt wth FMT_VERSION 80101
  • OpenCV 4.5.3
  • Microsoft Windows [Version 10.0.19044.1586]
  • VS2019 v16.11.10

Repro

  1. Create code that includes both fmt and OpenCV core, then calls one of the log outputters like spdlog::error("asdasd");
  2. Build with MSVC's code analyzer

Result

Build fails with errors indicating the the global OpenCV type uint is being hidden by fmt's local uint

[build] vcpkg_installed\x64-windows-static-md-v142-sdk10\include\fmt/format.h(2042): error C2220: the following warning is treated as an error
[build] vcpkg_installed\x64-windows-static-md-v142-sdk10\include\fmt/format.h(2042): warning C4459: declaration of 'uint' hides global declaration
[build] C:\repos-nobackup\opencv\.install\Release\include\opencv2/core/hal/interface.h(45): note: see declaration of 'uint'
[build] vcpkg_installed\x64-windows-static-md-v142-sdk10\include\fmt/format.h(2197): note: see reference to function template instantiation 'OutputIt fmt::v8::detail::write<Char,std::back_insert_iterator<fmt::v8::detail::buffer<T>>,double,0>(OutputIt,double)' being compiled
[build]         with
[build]         [
[build]             OutputIt=std::back_insert_iterator<fmt::v8::detail::buffer<wchar_t>>,
[build]             Char=wchar_t,
[build]             T=wchar_t
[build]         ]
[build] vcpkg_installed\x64-windows-static-md-v142-sdk10\include\fmt/core.h(1611): note: see reference to function template instantiation 'std::back_insert_iterator<fmt::v8::detail::buffer<T>> fmt::v8::detail::default_arg_formatter<Char>::operator ()<double>(double)' being compiled
[build]         with
[build]         [
[build]             T=wchar_t,
[build]             Char=wchar_t
[build]         ]
[build] vcpkg_installed\x64-windows-static-md-v142-sdk10\include\fmt/core.h(1611): note: see reference to function template instantiation 'std::back_insert_iterator<fmt::v8::detail::buffer<T>> fmt::v8::detail::default_arg_formatter<Char>::operator ()<double>(double)' being compiled
[build]         with
[build]         [
[build]             T=wchar_t,
[build]             Char=wchar_t
[build]         ]
[build] vcpkg_installed\x64-windows-static-md-v142-sdk10\include\fmt/format.h(2931): note: see reference to function template instantiation 'std::back_insert_iterator<fmt::v8::detail::buffer<T>> fmt::v8::visit_format_arg<fmt::v8::detail::default_arg_formatter<Char>,Context>(Visitor &&,const fmt::v8::basic_format_arg<Context> &)' being compiled
[build]         with
[build]         [
[build]             T=wchar_t,
[build]             Char=wchar_t,
[build]             Context=fmt::v8::wformat_context,
[build]             Visitor=fmt::v8::detail::default_arg_formatter<wchar_t>
[build]         ]
[build] vcpkg_installed\x64-windows-static-md-v142-sdk10\include\fmt/xchar.h(208): note: see reference to function template instantiation 'void fmt::v8::detail::vformat_to<T>(fmt::v8::detail::buffer<T> &,fmt::v8::basic_string_view<wchar_t>,fmt::v8::basic_format_args<fmt::v8::wformat_context>,fmt::v8::detail::locale_ref)' being compiled
[build]         with
[build]         [
[build]             T=wchar_t
[build]         ]
[build] vcpkg_installed\x64-windows-static-md-v142-sdk10\include\fmt/format.h(1270): warning C4459: declaration of 'uint' hides global declaration
[build] C:\repos-nobackup\opencv\.install\Release\include\opencv2/core/hal/interface.h(45): note: see declaration of 'uint'
[build] vcpkg_installed\x64-windows-static-md-v142-sdk10\include\fmt/format.h(2052): note: see reference to function template instantiation 'fmt::v8::detail::dragonbox::float_info<double>::carrier_uint fmt::v8::detail::exponent_mask<floaty>(void)' being compiled
[build] vcpkg_installed\x64-windows-static-md-v142-sdk10\include\fmt/format.h(2197): note: see reference to function template instantiation 'OutputIt fmt::v8::detail::write<Char,std::back_insert_iterator<fmt::v8::detail::buffer<T>>,double,0>(OutputIt,double)' being compiled
[build]         with
[build]         [
[build]             OutputIt=std::back_insert_iterator<fmt::v8::detail::buffer<wchar_t>>,
[build]             Char=wchar_t,
[build]             T=wchar_t
[build]         ]

Expected

Clean build, no errors.

Notes

uint only occurs 5 times throughout fmt. I request those 5 have a simple change to avoid the conflict.
For example, changing uint to dbox_uint

@vitaut
Copy link
Contributor

vitaut commented Mar 13, 2022

In general fixing nonsensical warnings like this is not a goal but a PR to suppress them would be welcome provided that it is not too intrusive.

@vitaut vitaut closed this as completed Mar 13, 2022
@diablodale
Copy link
Author

Ok. PR forthcoming...

@vitaut
Copy link
Contributor

vitaut commented Mar 14, 2022

On a second thought, we shouldn't be obfuscating local names like this just because of some random library. You could use FMT_SYSTEM_HEADERS or some other mechanism to suppress this warning without changing {fmt} or opencv.

@diablodale
Copy link
Author

Argh, I'm half-way through the repro code and PR.
I'll stop work now.

OpenCV is the "big bad" here. For other that read this, I've confirmed three workarounds

  1. Use something other than OpenCV
  2. Rename the local uint typename in the 5 location in fmt/format.h to anything else. Or remove the two using uint since it is not used but 3 times.
  3. Wrapping the load of fmt headers like...
#pragma warning(push)
#pragma warning(disable: 4459)
#include <fmt/format.h>
#pragma warning(pop)

@alexezeder
Copy link
Contributor

alexezeder commented Mar 14, 2022

If you use CMake then you could, as @vitaut has pointed out, pass FMT_SYSTEM_HEADERS flag (by setting it in your CMakeLists.txt before add_subdirectory(fmt)) to suppress all warnings from {fmt} library. As far as I can see, MSVC is also supported by CMake starting with version 3.22.

@shuffle2
Copy link

FMT_SYSTEM_HEADERS doesn't seem like a complete solution, because in the case of fmt, the warning comes from an external template (in fmt) instantiated in my project's code, and my project uses external:templates- specifically to still catch warnings in locally instantiated external templates.

So, while my project includes headers from multiple external(/"system") sources which also define the type uint, those definitions of uint are not a problem until they conflict with the uint which is created by some fmt code. While I can successfully use the external:anglebrackets and external:W0 settings to ignore the non-templated occurrences, fmt requires I specially disable external:templates- for source files where it becomes a problem.

I think it should be fixed in fmt...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants