OSDN Git Service

PR c++/36695
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 10 Jan 2009 11:48:06 +0000 (11:48 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 10 Jan 2009 11:48:06 +0000 (11:48 +0000)
* typeck2.c (build_functional_cast): Check for reference type and NULL
PARMS.

* g++.dg/ext/complex4.C: New test.
* g++.dg/ext/complex5.C: New test.
* g++.dg/init/reference1.C: New test.
* g++.dg/init/reference2.C: New test.
* g++.dg/init/reference3.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@143244 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/complex4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/complex5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/init/reference1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/init/reference2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/init/reference3.C [new file with mode: 0644]

index 1c16296..ad9b858 100644 (file)
@@ -1,3 +1,9 @@
+2009-01-10  Andrew Pinski  <pinskia@gmail.com>
+
+       PR c++/36695
+       * typeck2.c (build_functional_cast): Check for reference type and NULL
+       PARMS.
+
 2009-01-09  Steve Ellcey  <sje@cup.hp.com>
 
        * typeck.c (cp_build_unary_op): Check for ERROR_MARK.
index 60e4ef1..a19a999 100644 (file)
@@ -1445,6 +1445,12 @@ build_functional_cast (tree exp, tree parms, tsubst_flags_t complain)
   else
     type = exp;
 
+  if (TREE_CODE (type) == REFERENCE_TYPE && !parms)
+    {
+      error ("invalid value-initialization of reference types");
+      return error_mark_node;
+    }
+
   if (processing_template_decl)
     {
       tree t = build_min (CAST_EXPR, type, parms);
index 4765a8e..2180b46 100644 (file)
@@ -1,3 +1,12 @@
+2009-01-10  Andrew Pinski  <pinskia@gmail.com>
+
+       PR c++/36695
+       * g++.dg/ext/complex4.C: New test.
+       * g++.dg/ext/complex5.C: New test.
+       * g++.dg/init/reference1.C: New test.
+       * g++.dg/init/reference2.C: New test.
+       * g++.dg/init/reference3.C: New test.
+
 2009-01-10  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/38763
diff --git a/gcc/testsuite/g++.dg/ext/complex4.C b/gcc/testsuite/g++.dg/ext/complex4.C
new file mode 100644 (file)
index 0000000..78b9356
--- /dev/null
@@ -0,0 +1,5 @@
+// { dg-do compile }
+// This code used to be rejected as there was no conversion from int to float __complex__
+ #include <vector>
+ typedef float __complex__ fcomplex;
+ std::vector<fcomplex> vfc(10);
diff --git a/gcc/testsuite/g++.dg/ext/complex5.C b/gcc/testsuite/g++.dg/ext/complex5.C
new file mode 100644 (file)
index 0000000..4a29960
--- /dev/null
@@ -0,0 +1,6 @@
+/* PR c++/21210 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+typedef float __complex__ fcomplex;
+fcomplex cplx = fcomplex(0);
diff --git a/gcc/testsuite/g++.dg/init/reference1.C b/gcc/testsuite/g++.dg/init/reference1.C
new file mode 100644 (file)
index 0000000..7ce5f90
--- /dev/null
@@ -0,0 +1,11 @@
+// { dg-do compile }
+// This code used to be accepted but it is invalid as there is no
+// value initialization of a reference type.
+// PR c++/36695
+
+int main()
+{
+  typedef int& T;
+  T a = T();  // { dg-error "value-initialization of reference" }
+}
+
diff --git a/gcc/testsuite/g++.dg/init/reference2.C b/gcc/testsuite/g++.dg/init/reference2.C
new file mode 100644 (file)
index 0000000..42f5374
--- /dev/null
@@ -0,0 +1,13 @@
+// { dg-do compile }
+// This code used to be accepted but it is invalid as there is no
+// value initialization of a reference type.
+// PR c++/36695
+
+// We should we able to diagnostic this without instantiating the template
+template <int a1>
+int f()
+{
+  typedef int& T;
+  T a = T();  // { dg-error "value-initialization of reference" }
+}
+
diff --git a/gcc/testsuite/g++.dg/init/reference3.C b/gcc/testsuite/g++.dg/init/reference3.C
new file mode 100644 (file)
index 0000000..344e94e
--- /dev/null
@@ -0,0 +1,13 @@
+// { dg-do compile }
+// This code used to be accepted but it is invalid as there is no
+// value initialization of a reference type.
+// PR c++/36695
+
+template <typename T>
+T f()
+{
+  T a = T();  // { dg-error "value-initialization of reference" }
+}
+
+int &a = f<int&>(); // { dg-message "instantiated from here" }
+