首页 > 解决方案 > 为什么以下使用 boost 词法转换的程序在英特尔编译器上失败而不是 gcc(编译器错误)?

问题描述

我有以下非常简单的程序,在使用 boost::lexical_cast(boost 版本 1.67.0)时,它似乎在英特尔编译器上失败,但在 gcc 上却没有:

#include <boost/lexical_cast.hpp>
#include <string>
#include <iostream>

float getSomeNumber()
{
  return 10.0;
}

int main(int argc, char** argv)
{
   std::string mystring("Hello: " + boost::lexical_cast<std::string>(getSomeNumber());
   std::cout << mystring << std::endl;
   return 0;
}

编译时,Intel 返回以下错误:

 /boost/1.67.0/include/boost/type_traits/is_complete.hpp(45): warning #70: incomplete type is not allowed

       ok_tag<sizeof(T)> check_is_complete(int);
       detected during ....
       ...

/boost/1.67.0/include/boost/type_traits/is_complete.hpp(51): error: template instantiation resulted in unexpected function type of "boost::detail::ok_tag<1U> (int)" (the meaning of a name may have changed since the template declaration -- the type of the template is "boost::detail::ok_tag<sizeof(T)> (int)")
       ...

     detected during: 
        instantiation of "boost::detail::check_is_complete" based on template argument <void> at line 51
        instantiation of class "boost::is_complete<T> [with T=void]" at line 484 of "/Path/to/boost/include/boost/type_traits/is_convertible.hpp"
        ...
        instantiation of "Target boost::lexical_cast<Target, Source>(const Source &) [with Target=std::string, Source=float]" at line 11 of "boostTest.cc"

从这个错误中我能看出的最好的一点是编译器似乎无法完成模板解析,但最后它似乎完成了?我尝试在 gcc(4.8.5 版)下编译相同的东西,它工作正常。这段代码以前在 boost 1.64.0 和 gcc 和 Intel 下也能正常工作。

这是英特尔编译器中的错误,还是 boost 中的错误?有没有办法修改我的程序作为解决方法?

软件版本

海湾合作委员会:4.8.5

英特尔编译器:2015.3.187

提升:1.67.0

操作系统:RHEL 7.5(迈坡)

编译行:

icpc/gcc --std=c++11 boostTest.cc -o boostTest -Ipath/to/boost/include -lstdc++

标签: c++gccboostcompiler-errors

解决方案


推荐阅读