This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/71590] G++ template function initialize with wrong type


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71590

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
There is a (subtle) difference between the initialization in "std::string s =
a;" and the assignment in "std::string s; s = a;"  When valid, the
initialization invokes a constructor (possibly two), while the assignment
invokes the assignment operator.  But since std::string doesn't have a
constructor that takes just a char (or int) argument the initialization is
invalid.  (As mentioned, it does have an assignment operator that takes a
char.)

(For completeness' sake, in C++ 11, std::string has a constructor that takes a
std::initializer_list, and so with G++ a string object can be constructed like
so: "std::string s = { a };"  But this is a G++ extension and not a valid C++
11 construct so G++ will give a warning: narrowing conversion of âaâ from âintâ
to âcharâ inside { }.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]