c++sunstudio

const to non-const pointer template argument conversion


VC10 and GCC 4.4 accept the following, while Sun Studio 12 does not:

std::pair<char*, int> p1;
std::pair<char* const, int> p2;
p1 = p2

Sun Studio 12 complains:

Error: Cannot use std::pair<char*const, int> to initialize std::pair<char*, int>.

Any ideas why this is happening and how I can get Sun Studio to ignore this. I am working with a third party library, which would be a pain to rewrite just for this sort of thing.


Solution

  • It seems to be a known issue with Sun's std library.

    Your best bet may be to convince the author of the code to replace the assignment with:

    p1 = std::make_pair(p2.first, p2.second);
    

    Or at construction time:

    std::pair<char*, int> p1(p2.first, p2.second);