samedi 31 octobre 2015

differnt behaviour between clang and microsoft c++/QT5 with constructors and return values

According to microsoft visual studio 2013 (being built from QT creator, QT 5.4), this code is fine:

#include <string>
struct X {
  X(std::string const &) {};
};

X wibble() { return ""; }

clang however says

test.cpp(53) : error: no viable conversion from 'const char [1]' to 'X'
X wibble() { return ""; }

test.cpp(49) : note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const char [1]' to 'const X &' for 1st argument
struct X {

test.cpp(49) : note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'const char [1]' to 'X &&' for 1st argument
struct X {

test.cpp(50) : note: candidate constructor not viable: no known conversion from 'const char [1]' to 'const std::string &' (aka 'const basic_string<char, char_traits<char>, allocator<char> > &') for 1st argument
X(std::string const &) {};

It does the same thing with QString for what it's worth. Assuming clang is correct, why is it complaining?

Aucun commentaire:

Enregistrer un commentaire