【问题标题】:boost 1.73 messages reporting during project build在项目构建期间提升 1.73 消息报告
【发布时间】:2020-11-24 04:21:48
【问题描述】:

我在一个使用 Boost 1.48 的旧项目中使用 Boost 1.73。我的目的是修复过程中的所有警告和错误。

在编译项目时,我收到了一些奇怪的消息,这些消息不在项目的源代码中,而是在 boost 本身中,这些消息就像大多数错误消息一样,含糊不清而且没有多大帮助。

1>debugengine.cpp
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\utility(173): warning C4244: 'initializing': conversion from '_Ty' to '_Ty2', possible loss of data
1>        with
1>        [
1>            _Ty=int
1>        ]
1>        and
1>        [
1>            _Ty2=unsigned short
1>        ]
1>c:\boost\boost_1_73_0\boost\date_time\date_parsing.hpp(111): note: see reference to function template instantiation 'std::pair<const _Kty,_Ty>::pair<const char(&)[4],int,0>(_Other1,_Other2 &&) noexcept(false)' being compiled
1>        with
1>        [
1>            _Kty=std::string,
1>            _Ty=unsigned short,
1>            _Other1=const char (&)[4],
1>            _Other2=int
1>        ]
1>c:\boost\boost_1_73_0\boost\date_time\date_parsing.hpp(99): note: see reference to function template instantiation 'std::pair<const _Kty,_Ty>::pair<const char(&)[4],int,0>(_Other1,_Other2 &&) noexcept(false)' being compiled
1>        with
1>        [
1>            _Kty=std::string,
1>            _Ty=unsigned short,
1>            _Other1=const char (&)[4],
1>            _Other2=int
1>        ]
1>c:\boost\boost_1_73_0\boost\date_time\date_parsing.hpp(168): note: see reference to function template instantiation 'unsigned short boost::date_time::month_str_to_ushort<month_type>(const std::string &)' being compiled
1>c:\boost\boost_1_73_0\boost\date_time\gregorian\parsers.hpp(49): note: see reference to function template instantiation 'date_type boost::date_time::parse_date<boost::gregorian::date>(const std::string &,int)' being compiled
1>        with
1>        [
1>            date_type=boost::gregorian::date
1>        ]
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(54): note: see reference to class template instantiation 'boost::arg<9>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(53): note: see reference to class template instantiation 'boost::arg<8>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(52): note: see reference to class template instantiation 'boost::arg<7>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(51): note: see reference to class template instantiation 'boost::arg<6>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(50): note: see reference to class template instantiation 'boost::arg<5>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(49): note: see reference to class template instantiation 'boost::arg<4>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(48): note: see reference to class template instantiation 'boost::arg<3>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(47): note: see reference to class template instantiation 'boost::arg<2>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(46): note: see reference to class template instantiation 'boost::arg<1>' being compiled

有什么我可以做的吗?

我正在使用 MSVC 2017。

我已将问题缩小到一个文件,并注释掉了所有内容,除了:

#include <boost/date_time.hpp>

这是我在编译时得到的:

1>------ Build started: Project: Debug Service Group, Configuration: Debug Win32 ------
1>debugengine.cpp
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\utility(173): warning C4244: 'initializing': conversion from '_Ty' to '_Ty2', possible loss of data
1>        with
1>        [
1>            _Ty=int
1>        ]
1>        and
1>        [
1>            _Ty2=unsigned short
1>        ]
1>c:\boost\boost_1_73_0\boost\date_time\date_parsing.hpp(111): note: see reference to function template instantiation 'std::pair<const _Kty,_Ty>::pair<const char(&)[4],int,0>(_Other1,_Other2 &&) noexcept(false)' being compiled
1>        with
1>        [
1>            _Kty=std::string,
1>            _Ty=unsigned short,
1>            _Other1=const char (&)[4],
1>            _Other2=int
1>        ]
1>c:\boost\boost_1_73_0\boost\date_time\date_parsing.hpp(99): note: see reference to function template instantiation 'std::pair<const _Kty,_Ty>::pair<const char(&)[4],int,0>(_Other1,_Other2 &&) noexcept(false)' being compiled
1>        with
1>        [
1>            _Kty=std::string,
1>            _Ty=unsigned short,
1>            _Other1=const char (&)[4],
1>            _Other2=int
1>        ]
1>c:\boost\boost_1_73_0\boost\date_time\date_parsing.hpp(168): note: see reference to function template instantiation 'unsigned short boost::date_time::month_str_to_ushort<month_type>(const std::string &)' being compiled
1>c:\boost\boost_1_73_0\boost\date_time\gregorian\parsers.hpp(49): note: see reference to function template instantiation 'date_type boost::date_time::parse_date<boost::gregorian::date>(const std::string &,int)' being compiled
1>        with
1>        [
1>            date_type=boost::gregorian::date
1>        ]
1>Done building project "Debug Service Group.vcxproj".
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

【问题讨论】:

  • 这是最后一条消息吗?似乎您已经截断了有关模板实例化的一系列消息。错误的来源将是最后一条消息。
  • @john,我正要编辑帖子,因为我发现了其他内容。

标签: c++ c++11 boost


【解决方案1】:

警告是无害的。这是 boost\date_time\date_parsing.hpp 第 99 行中的源代码

    static std::map<std::string, unsigned short> month_map =
      { { "jan", 1 },  { "january", 1 },

如您所见,映射的值类型是 unsigned short,但它是用 int 值初始化的。

我对这个警告有点惊讶,您可能认为 MSVC 2017 足够聪明,可以意识到将 1 分配给 unsigned short 不是问题。

我没有收到关于 MSVC 2019 的任何警告

【讨论】:

  • 谢谢,为什么开发人员不将强制转换为 unsigned short 以防止出现警告?
  • @SPlatten 您必须向开发人员询问。也许他们只使用每个编译器的最新版本进行测试?请记住,这些人是志愿者,时间有限
  • 也许只有我一个人,我永远无法发布任何带有警告的编译内容。
猜你喜欢
  • 1970-01-01
  • 2019-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-21
  • 2018-04-16
  • 2013-01-25
  • 2012-10-01
相关资源
最近更新 更多