{
cand->second_conv = build_identity_conv (totype, NULL_TREE);
- /* If totype isn't a reference, and LOOKUP_NO_TEMP_BIND isn't
+ /* If totype isn't a reference, and LOOKUP_ONLYCONVERTING is
set, then this is copy-initialization. In that case, "The
result of the call is then used to direct-initialize the
object that is the destination of the copy-initialization."
We represent this in the conversion sequence with an
rvalue conversion, which means a constructor call. */
if (!TYPE_REF_P (totype)
+ && (flag_elide_constructors || (flags & LOOKUP_ONLYCONVERTING))
&& !(convflags & LOOKUP_NO_TEMP_BIND))
cand->second_conv
= build_conv (ck_rvalue, totype, cand->second_conv);
break;
};
+ tsubst_flags_t sub_complain = complain;
+ if (!flag_elide_constructors)
+ sub_complain &= ~tf_no_cleanup;
expr = convert_like (next_conversion (convs), expr, fn, argnum,
convs->kind == ck_ref_bind
? issue_conversion_warnings : false,
- c_cast_p, complain);
+ c_cast_p, sub_complain);
if (expr == error_mark_node)
return error_mark_node;
--- /dev/null
+// PR c++/100838
+// { dg-do run }
+// { dg-additional-options -fno-elide-constructors }
+
+extern "C" int puts (const char *);
+
+int c,d;
+class MyString {
+public:
+ MyString(const char* s = "") {
+ puts ("ctor");
+ ++c;
+ }
+ ~MyString() {
+ puts ("dtor");
+ ++d;
+ }
+ MyString(const MyString& s) {
+ puts ("copy ctor");
+ ++c;
+ }
+ MyString& operator=(const MyString& s);
+};
+
+int main() {
+ {
+ MyString s1 = "Hello";
+ puts ("main");
+ }
+ if (c != d)
+ __builtin_abort();
+}