+2007-10-12 Simon Martin <simartin@users.sourceforge.net>
+
+ PR c++/26698
+ * call.c (build_user_type_conversion_1): Do not consider conversion
+ functions to convert a (possibly cv-qualified) object to the (possibly
+ cv-qualified) same object type (or a reference to it), to a (possibly
+ cv-qualified) base class of that type (or a reference to it).
+
2007-10-12 Paolo Carlini <pcarlini@suse.de>
* pt.c (tsubst): Use template_parm_level_and_index.
ctors = lookup_fnfields (totype, complete_ctor_identifier, 0);
if (IS_AGGR_TYPE (fromtype))
- conv_fns = lookup_conversions (fromtype);
+ {
+ tree to_nonref = non_reference (totype);
+ if (same_type_ignoring_top_level_qualifiers_p (to_nonref, fromtype) ||
+ (CLASS_TYPE_P (to_nonref) && CLASS_TYPE_P (fromtype)
+ && DERIVED_FROM_P (to_nonref, fromtype)))
+ {
+ /* [class.conv.fct] A conversion function is never used to
+ convert a (possibly cv-qualified) object to the (possibly
+ cv-qualified) same object type (or a reference to it), to a
+ (possibly cv-qualified) base class of that type (or a
+ reference to it)... */
+ }
+ else
+ conv_fns = lookup_conversions (fromtype);
+ }
candidates = 0;
flags |= LOOKUP_NO_CONVERSION;
+2007-10-12 Simon Martin <simartin@users.sourceforge.net>
+
+ PR c++/26698
+ * g++.dg/conversion/op4.C: New test.
+
2007-10-12 Richard Sandiford <rsandifo@nildram.co.uk>
* g++.dg/torture/pr33572.C (main): Allow argc to be zero.
--- /dev/null
+/* PR c++/26698 */
+/* { dg-do "compile" } */
+
+struct X {
+ int x;
+ X (int i = 0) : x (i) {}
+ operator X& (void) const {
+ return *(new X);
+ }
+};
+
+void add_one (X & ref) { /* { dg-error "in passing argument" } */
+ ++ ref.x;
+}
+
+void foo() {
+ X const a (2);
+ add_one(a); /* { dg-error "invalid initialization of reference of type" } */
+}