"function was not considered");
}
+/* We're converting EXPR to TYPE. If that conversion involves a conversion
+ function and we're binding EXPR to a reference parameter of that function,
+ return true. */
+
+bool
+conv_binds_to_reference_parm_p (tree type, tree expr)
+{
+ conversion_obstack_sentinel cos;
+ conversion *c = implicit_conversion (type, TREE_TYPE (expr), expr,
+ /*c_cast_p=*/false, LOOKUP_NORMAL,
+ tf_none);
+ if (c && !c->bad_p && c->user_conv_p)
+ for (; c; c = next_conversion (c))
+ if (c->kind == ck_user)
+ for (z_candidate *cand = c->cand; cand; cand = cand->next)
+ if (cand->viable == 1)
+ for (size_t i = 0; i < cand->num_convs; ++i)
+ if (cand->convs[i]->kind == ck_ref_bind
+ && conv_get_original_expr (cand->convs[i]) == expr)
+ return true;
+
+ return false;
+}
+
#include "gt-cp-call.h"
extern tree get_function_version_dispatcher (tree);
extern bool any_template_arguments_need_structural_equality_p (tree);
extern void maybe_show_nonconverting_candidate (tree, tree, tree, int);
+extern bool conv_binds_to_reference_parm_p (tree, tree);
/* in class.cc */
extern tree build_vfield_ref (tree, tree);
warning_at (EXPR_LOCATION (init), OPT_Wuninitialized,
"reference %qD is not yet bound to a value when used "
"here", field);
- else if (!INDIRECT_TYPE_P (type) || is_this_parameter (d->member))
+ else if ((!INDIRECT_TYPE_P (type) || is_this_parameter (d->member))
+ && !conv_binds_to_reference_parm_p (type, init))
warning_at (EXPR_LOCATION (init), OPT_Wuninitialized,
"member %qD is used uninitialized", field);
*walk_subtrees = false;
G g;
A a2;
H() : g(a1) { }
- // ??? clang++ doesn't warn here
- H(int) : g(a2) { } // { dg-warning "member .H::a2. is used uninitialized" }
+ H(int) : g(a2) { } // { dg-bogus "member .H::a2. is used uninitialized" }
};
struct I {
--- /dev/null
+// PR c++/113987
+// { dg-do compile }
+// { dg-options "-Wuninitialized" }
+
+struct t1 {
+ t1(int);
+};
+struct t2 {
+ t2(int&, int = 0);
+ t2(double&, int = 0);
+};
+struct t3 {
+ t3(int&);
+};
+struct t4 {};
+void f1(int&);
+struct t {
+ t() :
+ v1(i), // { dg-warning "is used uninitialized" }
+ v2(i),
+ v3(i),
+ v4((f1(i), t4())),
+ v5(i) {}
+ t1 v1;
+ t2 v2;
+ t3 v3;
+ t4 v4;
+ t1 v5;
+ int i;
+ int j;
+};
+int main() { t v1; }