/* Let the normal code give the error. */
return NULL_TREE;
+ /* A glvalue initializer might be significant to a reference constructor
+ or conversion operator. */
+ if (!DECL_CONSTRUCTOR_P (c->cand->fn)
+ || (TYPE_REF_P (TREE_VALUE
+ (FUNCTION_FIRST_USER_PARMTYPE (c->cand->fn)))))
+ for (auto &ce : CONSTRUCTOR_ELTS (init))
+ if (non_mergeable_glvalue_p (ce.value))
+ return NULL_TREE;
+
tree first = CONSTRUCTOR_ELT (init, 0)->value;
conversion *fc = implicit_conversion (elttype, init_elttype, first, false,
LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING,
clk_class = 4, /* A prvalue of class or array type. */
clk_bitfield = 8, /* An lvalue for a bit-field. */
clk_packed = 16, /* An lvalue for a packed field. */
- clk_implicit_rval = 1<<5 /* An lvalue being treated as an xvalue. */
+ clk_implicit_rval = 1<<5, /* An lvalue being treated as an xvalue. */
+ clk_mergeable = 1<<6
};
/* This type is used for parameters and variables which hold
extern bool obvalue_p (const_tree);
extern bool xvalue_p (const_tree);
extern bool bitfield_p (const_tree);
+extern bool non_mergeable_glvalue_p (const_tree);
extern tree cp_stabilize_reference (tree);
extern bool builtin_valid_in_constant_expr_p (const_tree);
extern tree build_min (enum tree_code, tree, ...);
return op1_lvalue_kind;
case STRING_CST:
+ return clk_ordinary | clk_mergeable;
+
case COMPOUND_LITERAL_EXPR:
return clk_ordinary;
&& DECL_LANG_SPECIFIC (ref)
&& DECL_IN_AGGR_P (ref))
return clk_none;
+
+ if (DECL_MERGEABLE (ref))
+ return clk_ordinary | clk_mergeable;
+
/* FALLTHRU */
case INDIRECT_REF:
case ARROW_EXPR:
return (lvalue_kind (ref) & clk_bitfield);
}
+/* True if REF is a glvalue with a unique address, excluding mergeable glvalues
+ such as string constants. */
+
+bool
+non_mergeable_glvalue_p (const_tree ref)
+{
+ auto kind = lvalue_kind (ref);
+ return (kind != clk_none
+ && !(kind & (clk_class|clk_mergeable)));
+}
+
/* C++-specific version of stabilize_reference. */
tree
tree string_lit = build_string (4, "foo");
TREE_TYPE (string_lit) = char_array_type_node;
string_lit = fix_string_type (string_lit);
- ASSERT_EQ (clk_ordinary, lvalue_kind (string_lit));
+ ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (string_lit));
tree wrapped_string_lit = maybe_wrap_with_location (string_lit, loc);
ASSERT_TRUE (location_wrapper_p (wrapped_string_lit));
- ASSERT_EQ (clk_ordinary, lvalue_kind (wrapped_string_lit));
+ ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (wrapped_string_lit));
tree parm = build_decl (UNKNOWN_LOCATION, PARM_DECL,
get_identifier ("some_parm"),
--- /dev/null
+// PR c++/118673
+// { dg-do run { target c++11 } }
+
+#include <initializer_list>
+
+struct ArrayRef {
+ const int *Data = nullptr;
+ ArrayRef(const int &OneElt) : Data(&OneElt) {}
+};
+
+struct Vec
+{
+ ArrayRef Elts[1];
+ Vec(std::initializer_list<ArrayRef> IL)
+ : Elts{*IL.begin()}
+ { }
+};
+
+[[gnu::noinline]] Vec fn() {
+ static const auto extension = 42;
+ return {extension};
+}
+int main() {
+ auto t = fn();
+ if (t.Elts[0].Data[0] != 42) __builtin_abort();
+}