const int flags = direct_init_p ? LOOKUP_NORMAL : LOOKUP_IMPLICIT;
conversion *conv = implicit_conversion (type, TREE_TYPE (expr), expr,
/*c_cast_p=*/false, flags, tf_none);
- tristate ret (tristate::TS_UNKNOWN);
- if (conv && !conv->bad_p)
- ret = tristate (conv_binds_ref_to_temporary (conv));
+ if (!conv || conv->bad_p)
+ return tristate::unknown ();
- return ret;
+ if (conv_binds_ref_to_temporary (conv))
+ {
+ /* Actually perform the conversion to check access control. */
+ if (convert_like (conv, expr, tf_none) != error_mark_node)
+ return tristate (true);
+ else
+ return tristate::unknown ();
+ }
+
+ return tristate (false);
}
/* Call the trivial destructor for INSTANCE, which can be either an lvalue of
--- /dev/null
+// PR c++/120529
+// { dg-do compile { target c++11 } }
+
+#define SA(X) static_assert((X),#X)
+
+class Dst {};
+
+class Src {
+private:
+ operator Dst() const;
+};
+
+class Src2 {
+protected:
+ operator Dst() const;
+};
+
+class Src3 {
+public:
+ operator Dst() const;
+};
+
+SA (!__reference_converts_from_temporary (Dst&&, Src));
+SA (!__reference_constructs_from_temporary (Dst&&, Src));
+SA (!__reference_converts_from_temporary (Dst&&, Src2));
+SA (!__reference_constructs_from_temporary (Dst&&, Src2));
+SA (__reference_converts_from_temporary (Dst&&, Src3));
+SA (__reference_constructs_from_temporary (Dst&&, Src3));