C++ – Have there ever been silent behavior changes in C++ with new standard versions

clanguage-lawyerstandardization

(I'm looking for an example or two to prove the point, not a list.)

Has it ever been the case that a change in the C++ standard (e.g. from 98 to 11, 11 to 14 etc.) changed the behavior of existing, well-formed, defined-behavior user code – silently? i.e. with no warning or errors when compiling with the newer standard version?

Notes:

  • I'm asking about standards-mandated behavior, not about implementer/compiler author choices.
  • The less contrived the code, the better (as an answer to this question).
  • I don't mean code with version detection such as #if __cplusplus >= 201103L.
  • Answers involving the memory model are fine.

Best Answer

The return type of string::data changes from const char* to char* in C++ 17. That could certainly make a difference

void func(char* data)
{
    cout << data << " is not const\n";
}

void func(const char* data)
{
    cout << data << " is const\n";
}

int main()
{
    string s = "xyz";
    func(s.data());
}

A bit contrived but this legal program would change its output going from C++14 to C++17.

Related Topic