Clang behaves differently than msvc ++ and gcc

This code behaves amazingly on Clang. Is there a bug in Clang or gcc and MSVC ++ is wrong? Or undefined behavior ?:

typedef set<int> A;
typedef map<int,A> B;
B gcctest;
A def;

A const& get(int key)
{
    B::const_iterator j = gcctest.find(key);
    if (j != gcctest.end())
        return j->second;
    return def;
}

int main()
{
    def.insert(1);
    int t = 47;
    gcctest[t] = get(t);
    cerr << (gcctest[t].size() ? "gcc or msvc++" : "clang") << endl;
}

It seems that Clang is inserting the default built element on my map before calling get. This does not happen if it Ais a simple type, for example. int.

on GCC and MSVC ++++ it prints gcc or msvC ++. On clang in prints clang.

GCC on Linux 4.6.3

Clang on MacOS Xcode 5.0.2

MSVC ++ on Windows VS2012

(PS: please help me with a better heading for this question.)

+4
source share
1 answer

std::map<K, T>, , , . , ,

gcctest[t] = get(t);

. , , .

+2

All Articles