c++ - 英特尔 C++ 编译器 - const 字符串是可修改的

标签 c++ compiler-bug

我编写了以下代码:

#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 也会对其进行修改。 我正在使用 Intel 的 16.0.2 编译器

在其他编译器(如 g++)上,此代码会引发编译错误。

最佳答案

根据 a post on Intel's developer zone ,这是英特尔编译器的一个错误,已在版本 16.0.3(更新 3)中修复。

引用 Judith Ward(英特尔)(2016 年 2 月 5 日):

The underlying problem is that our compiler suppressed discretionary errors that come from system headers (like string and stl_algo.h).

We need to make an exception for errors that are actually useful (i.e. indicative of a potential runtime problem) like this one. This was recently already submitted by another user as DPD200380931 and we just fixed it and have confirmed fixes this problem. This fix did not make the code cutoff for 16.0 update 2 but will be in 16.0 update 3.

关于c++ - 英特尔 C++ 编译器 - const 字符串是可修改的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39348017/

相关文章:

c++ - 使用 GDI 或 GDI+ 的高级图形

c++ - 试图仅在 g++ 的宏中使 -Waggregate-return 保持沉默 - 错误的编译器?

c++ - Visual C++ 2012 (x86) 中可能的编译器错误?

c++ - VS2008 SP1 : No appropriate default constructor available when pushing a pair into vector

c++ - 覆盖说明符作为模板参数 - 它有效吗?

c++ - 将模板化类型初始化为 "zero"

c++ - qobject_cast 是如何工作的?

c++ - 内部类声明

C++98 诉 C++11 std::set::insert 规范

c++ - Template模板和CRTP : compiler bugs,和GCC和clang不一致