I coded the following:
#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;
}
This compiles, and the output is "A". Even though the function takes a const
reference, to_upper
modifies it.
I'm using Intel's 16.0.2 compiler
On other compilers (like g++), this code throws a compilation error.
According to a post on Intel's developer zone, it's a bug with the Intel compiler that was fixed in version 16.0.3 (update 3).
Quoting Judith Ward (Intel) (02/05/2016):
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.