如何使用 gcc 抑制 boost::thread 警告?

发布于 2024-09-24 06:38:47 字数 4711 浏览 4 评论 0原文

在我的项目中,我最近决定使用 boost::thread。我的代码在 Linux 下编译得很好,但在 Windows(x86 或 x64)下,我在 gcc 4.5 中收到以下警告:

In file included from C:\Boost\include\boost-1_44/boost/thread/shared_mutex.hpp:14:0,
                 from C:\Boost\include\boost-1_44/boost/thread/detail/thread_group.hpp:9,
                 from C:\Boost\include\boost-1_44/boost/thread/thread.hpp:24,
                 from C:\Boost\include\boost-1_44/boost/thread.hpp:13,
                 from include\systools/upnp_control_point.hpp:50,
                 from src\upnp_control_point.cpp:45:
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp: In member function 'T boost::shared_mutex::interlocked_
compare_exchange(T*, T, T) [with T = boost::shared_mutex::state_data]':
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:110:103:   instantiated from here
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:50:99: error: dereferencing type-punned pointer will bre
ak strict-aliasing rules
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:50:99: error: dereferencing type-punned pointer will bre
ak strict-aliasing rules
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:51:52: error: dereferencing type-punned pointer will bre
ak strict-aliasing rules
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:51:52: error: dereferencing type-punned pointer will bre
ak strict-aliasing rules
In file included from C:\Boost\include\boost-1_44/boost/algorithm/string/detail/find_format.hpp:18:0,
                 from C:\Boost\include\boost-1_44/boost/algorithm/string/find_format.hpp:23,
                 from C:\Boost\include\boost-1_44/boost/algorithm/string/replace.hpp:22,
                 from C:\Boost\include\boost-1_44/boost/date_time/date_facet.hpp:17,
                 from C:\Boost\include\boost-1_44/boost/date_time/gregorian/gregorian_io.hpp:16,
                 from C:\Boost\include\boost-1_44/boost/date_time/gregorian/gregorian.hpp:31,
                 from C:\Boost\include\boost-1_44/boost/date_time/posix_time/time_formatters.hpp:12,
                 from C:\Boost\include\boost-1_44/boost/date_time/posix_time/posix_time.hpp:24,
                 from include\systools/upnp_device.hpp:51,
                 from include\systools/upnp_control_point.hpp:48,
                 from src\upnp_control_point.cpp:45:
C:\Boost\include\boost-1_44/boost/algorithm/string/detail/find_format_store.hpp: At global scope:
C:\Boost\include\boost-1_44/boost/algorithm/string/detail/find_format_store.hpp: In instantiation of 'bool boost::algori
thm::detail::check_find_result(InputT&, FindResultT&) [with InputT = std::basic_string<char>, FindResultT = boost::itera
tor_range<__gnu_cxx::__normal_iterator<char*, std::basic_string<char> > >]':
C:\Boost\include\boost-1_44/boost/algorithm/string/detail/find_format_all.hpp:259:17:   instantiated from 'void boost::a
lgorithm::detail::find_format_all_impl(InputT&, FinderT, FormatterT, FindResultT) [with InputT = std::basic_string<char>
, FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algori
thm::detail::const_formatF<boost::iterator_range<const char*> >, FindResultT = boost::iterator_range<__gnu_cxx::__normal
_iterator<char*, std::basic_string<char> > >]'
C:\Boost\include\boost-1_44/boost/algorithm/string/find_format.hpp:268:13:   instantiated from 'void boost::algorithm::f
ind_format_all(SequenceT&, FinderT, FormatterT) [with SequenceT = std::basic_string<char>, FinderT = boost::algorithm::d
etail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algorithm::detail::const_formatF<boos
t::iterator_range<const char*> >]'
C:\Boost\include\boost-1_44/boost/algorithm/string/replace.hpp:654:13:   instantiated from 'void boost::algorithm::repla
ce_all(SequenceT&, const Range1T&, const Range2T&) [with SequenceT = std::basic_string<char>, Range1T = char [15], Range
2T = char [1]]'
C:\Boost\include\boost-1_44/boost/units/detail/utility.hpp:50:51:   instantiated from here
C:\Boost\include\boost-1_44/boost/algorithm/string/detail/find_format_store.hpp:74:18: error: unused parameter 'Input'
scons: *** [src\upnp_control_point.o] Error 1
scons: building terminated because of errors.

我刚刚在我自己的 中包含 .cpp 文件,没什么特别的。

由于我无法控制 boost 的代码,有没有办法暂时抑制这些警告?比如:

#super_killing_macro_that_disable_some_warnings
#include <boost/thread.hpp>
#its_all_good_know_i_want_my_warnings_back

我能做什么?

In my project, I recently decided to use boost::thread. My code compiles fine under Linux, but under Windows (either x86 or x64), I get the following warnings with gcc 4.5:

In file included from C:\Boost\include\boost-1_44/boost/thread/shared_mutex.hpp:14:0,
                 from C:\Boost\include\boost-1_44/boost/thread/detail/thread_group.hpp:9,
                 from C:\Boost\include\boost-1_44/boost/thread/thread.hpp:24,
                 from C:\Boost\include\boost-1_44/boost/thread.hpp:13,
                 from include\systools/upnp_control_point.hpp:50,
                 from src\upnp_control_point.cpp:45:
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp: In member function 'T boost::shared_mutex::interlocked_
compare_exchange(T*, T, T) [with T = boost::shared_mutex::state_data]':
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:110:103:   instantiated from here
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:50:99: error: dereferencing type-punned pointer will bre
ak strict-aliasing rules
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:50:99: error: dereferencing type-punned pointer will bre
ak strict-aliasing rules
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:51:52: error: dereferencing type-punned pointer will bre
ak strict-aliasing rules
C:\Boost\include\boost-1_44/boost/thread/win32/shared_mutex.hpp:51:52: error: dereferencing type-punned pointer will bre
ak strict-aliasing rules
In file included from C:\Boost\include\boost-1_44/boost/algorithm/string/detail/find_format.hpp:18:0,
                 from C:\Boost\include\boost-1_44/boost/algorithm/string/find_format.hpp:23,
                 from C:\Boost\include\boost-1_44/boost/algorithm/string/replace.hpp:22,
                 from C:\Boost\include\boost-1_44/boost/date_time/date_facet.hpp:17,
                 from C:\Boost\include\boost-1_44/boost/date_time/gregorian/gregorian_io.hpp:16,
                 from C:\Boost\include\boost-1_44/boost/date_time/gregorian/gregorian.hpp:31,
                 from C:\Boost\include\boost-1_44/boost/date_time/posix_time/time_formatters.hpp:12,
                 from C:\Boost\include\boost-1_44/boost/date_time/posix_time/posix_time.hpp:24,
                 from include\systools/upnp_device.hpp:51,
                 from include\systools/upnp_control_point.hpp:48,
                 from src\upnp_control_point.cpp:45:
C:\Boost\include\boost-1_44/boost/algorithm/string/detail/find_format_store.hpp: At global scope:
C:\Boost\include\boost-1_44/boost/algorithm/string/detail/find_format_store.hpp: In instantiation of 'bool boost::algori
thm::detail::check_find_result(InputT&, FindResultT&) [with InputT = std::basic_string<char>, FindResultT = boost::itera
tor_range<__gnu_cxx::__normal_iterator<char*, std::basic_string<char> > >]':
C:\Boost\include\boost-1_44/boost/algorithm/string/detail/find_format_all.hpp:259:17:   instantiated from 'void boost::a
lgorithm::detail::find_format_all_impl(InputT&, FinderT, FormatterT, FindResultT) [with InputT = std::basic_string<char>
, FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algori
thm::detail::const_formatF<boost::iterator_range<const char*> >, FindResultT = boost::iterator_range<__gnu_cxx::__normal
_iterator<char*, std::basic_string<char> > >]'
C:\Boost\include\boost-1_44/boost/algorithm/string/find_format.hpp:268:13:   instantiated from 'void boost::algorithm::f
ind_format_all(SequenceT&, FinderT, FormatterT) [with SequenceT = std::basic_string<char>, FinderT = boost::algorithm::d
etail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algorithm::detail::const_formatF<boos
t::iterator_range<const char*> >]'
C:\Boost\include\boost-1_44/boost/algorithm/string/replace.hpp:654:13:   instantiated from 'void boost::algorithm::repla
ce_all(SequenceT&, const Range1T&, const Range2T&) [with SequenceT = std::basic_string<char>, Range1T = char [15], Range
2T = char [1]]'
C:\Boost\include\boost-1_44/boost/units/detail/utility.hpp:50:51:   instantiated from here
C:\Boost\include\boost-1_44/boost/algorithm/string/detail/find_format_store.hpp:74:18: error: unused parameter 'Input'
scons: *** [src\upnp_control_point.o] Error 1
scons: building terminated because of errors.

I just included <boost/thread.hpp> in my own .cpp file, nothing special.

Since I have no control over boost's code, is there a way to suppress those warnings temporarily ? Something like:

#super_killing_macro_that_disable_some_warnings
#include <boost/thread.hpp>
#its_all_good_know_i_want_my_warnings_back

What can I do ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

儭儭莪哋寶赑 2024-10-01 06:38:47

我刚刚发现了 -isystem 选项,它允许将目录包含为系统目录。这些目录中的文件不会发出任何警告,因此它似乎非常适合我的任务。

此外,这还有一个巧妙的副作用,使 SCons 也忽略依赖树中的这些目录。因为我不希望这些库经常改变,所以没关系。

I just discovered the -isystem option that allow to include a directory as a system directory. No warnings are emited from files within thoses directories so it seems perfect for my task.

Also, this has the neat side effect to make SCons ignore those directories as well in the dependency tree. Since I'm not expecting those libraries to change often, it's fine.

执着的年纪 2024-10-01 06:38:47

您可能会在诊断杂注方面有一些运气:
http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas。 html

you may have some luck with diagnostic pragma:
http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html

久随 2024-10-01 06:38:47

我在 Windows XP SP3 上遇到了几乎相同的警告,并且从 mingw-get-inst-20101030 安装了 MinGW,并使用 GCC 4.5.0 和 boost 1.45.0 构建,如此处所示

http://fw-geekycoder.blogspot.com/2010/12/building-boost-using-mingw.html

我正在使用 BOOST_THREAD_USE_LIB 编译器标志和 -lboost_thread-mgw45-mt-1_45 链接器标志。我收到的唯一四个警告如下在本文末尾。

C:\workspace\boost_1_45_0/boost/thread/win32/shared_mutex.hpp:113:103:从这里实例化
C:\workspace\boost_1_45_0/boost/thread/win32/shared_mutex.hpp:53:99:警告:取消引用类型双关指针将违反严格别名规则
C:\workspace\boost_1_45_0/boost/thread/win32/shared_mutex.hpp:53:99:警告:取消引用类型双关指针将违反严格别名规则
C:\workspace\boost_1_45_0/boost/thread/win32/shared_mutex.hpp:54:52:警告:取消引用类型双关指针将违反严格别名规则
C:\workspace\boost_1_45_0/boost/thread/win32/shared_mutex.hpp:54:52:警告:取消引用类型双关指针将违反严格别名规则

我还无法使生成的代码不崩溃,所以我不知道这些警告是否重要(通过检查线程是否改变了我的数值结果)。

I am having almost the same warnings on Windows XP SP3 with MinGW installed from mingw-get-inst-20101030 with GCC 4.5.0 and boost 1.45.0 built as indicated here

http://fw-geekycoder.blogspot.com/2010/12/building-boost-using-mingw.html

I am using the BOOST_THREAD_USE_LIB compiler flag and the -lboost_thread-mgw45-mt-1_45 linker flag. The only four warnings I am getting are as follows at the end of this post.

C:\workspace\boost_1_45_0/boost/thread/win32/shared_mutex.hpp:113:103: instantiated from here
C:\workspace\boost_1_45_0/boost/thread/win32/shared_mutex.hpp:53:99: warning: dereferencing type-punned pointer will break strict-aliasing rules
C:\workspace\boost_1_45_0/boost/thread/win32/shared_mutex.hpp:53:99: warning: dereferencing type-punned pointer will break strict-aliasing rules
C:\workspace\boost_1_45_0/boost/thread/win32/shared_mutex.hpp:54:52: warning: dereferencing type-punned pointer will break strict-aliasing rules
C:\workspace\boost_1_45_0/boost/thread/win32/shared_mutex.hpp:54:52: warning: dereferencing type-punned pointer will break strict-aliasing rules

I haven't been able to get the resulting code not to crash yet, so I don't know if these warnings are important or not (by checking to see if threading changes my numerical results).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文