@@ -931,13 +931,9 @@ static void
cp_genericize_target_expr (tree *stmt_p)
{
tree slot = TARGET_EXPR_SLOT (*stmt_p);
- /* If TARGET_EXPR is created for some global var initializer, the slot
- will have NULL and so is_local_temp will return false for it. If
- this is a ssdf, set DECL_CONTEXT now. */
- if (DECL_CONTEXT (slot) == NULL_TREE)
- DECL_CONTEXT (slot) = current_function_decl;
cp_genericize_init (&TARGET_EXPR_INITIAL (*stmt_p),
TARGET_EXPR_INITIAL (*stmt_p), slot);
+ gcc_assert (!DECL_INITIAL (slot));
}
/* Genericization context. */
@@ -557,8 +557,7 @@ bool
is_local_temp (tree decl)
{
return (VAR_P (decl) && DECL_ARTIFICIAL (decl)
- && !TREE_STATIC (decl)
- && DECL_FUNCTION_SCOPE_P (decl));
+ && !TREE_STATIC (decl));
}
/* Set various status flags when building an AGGR_INIT_EXPR object T. */
new file mode 100644
@@ -0,0 +1,39 @@
+// PR c++/104182
+// { dg-do run { target c++11 } }
+
+#include <initializer_list>
+
+int b;
+
+struct stringy {
+ const char *p;
+ stringy(const char *p): p(p) { ++b; }
+ const char& operator[](int i) const { return p[i]; }
+ ~stringy() { --b; }
+};
+
+struct S
+{
+ int A;
+ stringy B;
+};
+
+struct veccy {
+ S s;
+ veccy (const std::initializer_list<S> &l): s(*l.begin()) {}
+ const S& operator[](int i) const { return s; }
+};
+
+struct V
+{
+ veccy v;
+};
+
+static const V v{ { { { 237, "2" } } } };
+
+int main()
+{
+ if (v.v[0].A != 237 || v.v[0].B[0] != '2')
+ __builtin_abort();
+ return 0;
+}