boostorg / serialization

Boost.org serialization module
http://boost.org/libs/serialization
119 stars 139 forks source link

BOOST_ATTRIBUTE_UNUSED seems to have no effect in Visual Studio #271

Closed mojca closed 1 year ago

mojca commented 1 year ago

I'm compiling Boost 1.80.0 from source as part of a large project build. I'm using GitHub actions on windows-2022 with Visual Studio 2022, CMake and "treat warnings as errors" turned on.

I'm hitting the following error:

D:\a\Project\build\__external\src\boost\libs\serialization\include\boost/archive/iterators/wchar_from_mb.hpp(170,31): error C2220: the following warning is treated as an error (compiling source file D:\a\Project\build\__external\src\boost\libs\serialization\src\xml_woarchive.cpp) [D:\a\Project\build\_deps\boost-build\libs\serialization\boost_wserialization.vcxproj]
D:\a\Project\build\__external\src\boost\libs\serialization\include\boost/archive/iterators/wchar_from_mb.hpp(170,31): warning C4189: 'r': local variable is initialized but not referenced (compiling source file D:\a\Project\build\__external\src\boost\libs\serialization\src\xml_woarchive.cpp) [D:\a\Project\build\_deps\boost-build\libs\serialization\boost_wserialization.vcxproj]
D:\a\Project\build\__external\src\boost\libs\serialization\include\boost/archive/iterators/wchar_from_mb.hpp(149): message : while compiling class template member function 'void boost::archive::iterators::wchar_from_mb<boost::archive::iterators::xml_escape<InputIterator>>::drain(void)' [D:\a\Project\build\_deps\boost-build\libs\serialization\boost_wserialization.vcxproj]

I have found:

It seems as if VS 2022 doesn't properly understand BOOST_ATTRIBUTE_UNUSED.

mojca commented 1 year ago

Would a fix like this be acceptable?

diff --git a/include/boost/config/detail/suffix.hpp b/include/boost/config/detail/suffix.hpp
index 13d4bb6a..4b25f764 100644
--- a/include/boost/config/detail/suffix.hpp
+++ b/include/boost/config/detail/suffix.hpp
@@ -1039,7 +1039,11 @@ namespace std{ using ::type_info; }
 // Unused variable/typedef workarounds:
 //
 #ifndef BOOST_ATTRIBUTE_UNUSED
-#  define BOOST_ATTRIBUTE_UNUSED
+#  if __cplusplus < 201703L
+#    define BOOST_ATTRIBUTE_UNUSED
+#  else
+#    define BOOST_ATTRIBUTE_UNUSED [[maybe_unused]]
+#  endif
 #endif
 //
 // [[nodiscard]]:
jzmaddock commented 1 year ago

I'll look into this shortly.