Fix for c++/PR57958
authorDinar Temirbulatov <dtemirbulatov@gmail.com>
Wed, 23 Apr 2014 19:34:08 +0000 (23:34 +0400)
committerDinar Temirbulatov <dinar@gcc.gnu.org>
Wed, 23 Apr 2014 19:34:08 +0000 (23:34 +0400)
From-SVN: r209721

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/g++.dg/cpp0x/pr57958.C [new file with mode: 0644]

index 854cc4b21a4c273dd2745b3bd809fe22d97c9005..072195bddaed2fda88330ff5afecd63543c5e79e 100644 (file)
@@ -1,3 +1,9 @@
+2014-04-23 Dinar Temirbulatov  <dtemirbulatov@gmail.com>
+
+       PR c++/57958
+       * semantics.c (apply_deduced_return_type): Complete non-void type
+       before estimating whether the type is aggregate.
+
 2014-04-22  Marc Glisse  <marc.glisse@inria.fr>
 
        PR libstdc++/43622
index 795086a5854331d82de802c06478c1ae084f6733..3f8ca44904e59378c6f3aafbeb2670890d90aadb 100644 (file)
@@ -10650,6 +10650,8 @@ apply_deduced_return_type (tree fco, tree return_type)
 
   if (!processing_template_decl)
     {
+      if (!VOID_TYPE_P (TREE_TYPE (result)))
+       complete_type_or_else (TREE_TYPE (result), NULL_TREE);
       bool aggr = aggregate_value_p (result, fco);
 #ifdef PCC_STATIC_STRUCT_RETURN
       cfun->returns_pcc_struct = aggr;
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr57958.C b/gcc/testsuite/g++.dg/cpp0x/pr57958.C
new file mode 100644 (file)
index 0000000..d35f9ed
--- /dev/null
@@ -0,0 +1,39 @@
+// { dg-do run { target c++11 } }
+
+#define assert(E) if(!(E))__builtin_abort();
+
+int n = 0;
+
+template <class T>
+class Foo {
+ public:
+  Foo() { 
+   n--; 
+  }
+  Foo(const Foo&) { 
+   n--; 
+  }
+  ~Foo() { 
+   n++; 
+  }
+};
+
+struct Data {};
+
+void a()
+{
+       Data b;
+}
+
+int main(int argc, char *argv[]) {
+  auto fn = [] (const Foo<Data>& x) {
+    return (x);
+  };
+
+  {
+    Foo<Data> a;
+    fn(a);
+  }
+
+  assert(n == 0);
+}