簡體   English   中英

英特爾C ++編譯器 - const字符串是可修改的

[英]Intel C++ compiler - const string is modifiable

我編碼如下:

#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(英特爾)(2016年5月2日)

根本問題是我們的編譯器抑制了來自系統頭的任意錯誤(如string和stl_algo.h)。

我們需要對像這樣的實際有用的錯誤(即指示潛在的運行時問題)做一個例外。 這最近已經由另一個用戶提交為DPD200380931,我們剛剛修復了它並確認修復了這個問題。 此修復程序沒有使16.0更新2的代碼截止,但將在16.0更新3中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM