3

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.

Ivan Rubinson
  • 3,001
  • 4
  • 19
  • 48
mftrmbn
  • 113
  • 1
  • 5
  • Are you sure it compiles? What boost version and compiler? – juanchopanza Sep 06 '16 at 11:33
  • 1
    On gcc 5.4, this gives an error for the call to `to_upper`. – Ami Tavory Sep 06 '16 at 11:37
  • 1
    I am using boost 1.61.0 and the Intel 16.0.2 compiler and it compiles for sure. Now I tested it also with gcc. With gcc it fails during compilation. So, does that mean that there is an issue with the intel compiler? – mftrmbn Sep 06 '16 at 11:43
  • 2
    The code is invalid. If you're running something, it's gonna be old code/different binary. Try "full rebuild" or manually removing any binaries that could be confusing you. – sehe Sep 06 '16 at 11:47
  • 1
    @mftrmbn: The C++ standard says that modifying const memory results in undefined behavior. There's either a bug in the Intel compiler, or some other tom-foolery at hand. Is this the *exact* snippet you're compiling? Remove other includes, and please show all compile flags. – AndyG Sep 06 '16 at 12:03
  • 1
    I compile with `icpc -std=c++11 -I/path/to/boost/ main.cpp`. I am absolutely sure that there is no issue with old object files or binaries. The compilation with the above command runs without any warnings or errors. The example is exactly the code I run. I had found the issue in one of my production codes and I was confused by the behaviour. Thus, I built this minimal example to reproduce the issue. – mftrmbn Sep 06 '16 at 12:07
  • @mftrmbn: Can you navigate to the boost header "boost/algorithm/string/case_conv.hpp" and check the declaration for "to_upper"? What does it look like for you? – AndyG Sep 06 '16 at 12:09

1 Answers1

4

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.

Ivan Rubinson
  • 3,001
  • 4
  • 19
  • 48