public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-6822] c++: array temporary at file scope [PR104182]
@ 2022-01-23  3:19 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2022-01-23  3:19 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:9718bc4b03c1a94f7cf64860bbc828aa53c56234

commit r12-6822-g9718bc4b03c1a94f7cf64860bbc828aa53c56234
Author: Jason Merrill <jason@redhat.com>
Date:   Sat Jan 22 17:11:54 2022 -0500

    c++: array temporary at file scope [PR104182]
    
    This is the same issue as PR104031, but that patch doesn't fix this
    testcase because in this case, current_function_decl isn't set when we get
    to cp_genericize_target_expr.  But there seems to be no need for
    is_local_temp to check for function scope; !TREE_STATIC should be enough.
    
            PR c++/104182
    
    gcc/cp/ChangeLog:
    
            * cp-gimplify.cc (cp_genericize_target_expr): Make sure nothing
            has set DECL_INITIAL on a TARGET_EXPR slot.
            * tree.cc (is_local_temp): Don't check DECL_CONTEXT.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/initlist127.C: New test.

Diff:
---
 gcc/cp/cp-gimplify.cc                    |  6 +----
 gcc/cp/tree.cc                           |  3 +--
 gcc/testsuite/g++.dg/cpp0x/initlist127.C | 39 ++++++++++++++++++++++++++++++++
 3 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
index 0166ef690d2..d1c653c5fda 100644
--- a/gcc/cp/cp-gimplify.cc
+++ b/gcc/cp/cp-gimplify.cc
@@ -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.  */
diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index f88006aec4f..5d453e49717 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -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.  */
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist127.C b/gcc/testsuite/g++.dg/cpp0x/initlist127.C
new file mode 100644
index 00000000000..ebe5924bbf9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist127.C
@@ -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;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-23  3:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-23  3:19 [gcc r12-6822] c++: array temporary at file scope [PR104182] Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).