Intel c++编译器- const string是可修改的



我编写了如下代码:

#include <string>
#include <iostream>
#include <boost/algorithm/string.hpp>
using namespace std;
string encode(const string& word) { 
    boost::algorithm::to_upper(word);
    return word;
} 
int main() {
    string word = "a";
    string word1 = encode(word);
    cout << word << endl;
}

编译后,输出为"A"。即使函数使用const引用,to_upper也会修改它。我正在使用英特尔的16.0.2编译器

在其他编译器(如g++)上,此代码抛出编译错误。

根据英特尔开发者专区的一篇文章,这是英特尔编译器的一个错误,在16.0.3版本(更新3)中得到修复。

引用Judith Ward (Intel) (02/05/2016):

潜在的问题是我们的编译器抑制了来自系统头文件(如string和stl_algorithm .h)的任意错误。

我们需要为实际有用的错误(即指示潜在的运行时问题)创建一个异常,就像这样。最近已经有另一个用户以DPD200380931的名义提交了这个问题,我们刚刚修复了它,并且已经确认修复了这个问题。此修复没有使16.0更新2的代码中断,但将在16.0更新3。

最新更新