]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/70267
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 18 Mar 2016 07:59:36 +0000 (07:59 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 18 Mar 2016 07:59:36 +0000 (07:59 +0000)
* init.c (build_new_1): Complain and return error_mark_node
if alloc_fn is not _Jv_AllocObject function returning pointer.

* g++.dg/ext/java-3.C: New test.

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

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/java-3.C [new file with mode: 0644]

index 7e3ceeb5d29efdba77eec6b357833d1faac81862..75530b6dc30d4301460b58184bca8f0db69a2ec2 100644 (file)
@@ -1,3 +1,9 @@
+2016-03-18  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/70267
+       * init.c (build_new_1): Complain and return error_mark_node
+       if alloc_fn is not _Jv_AllocObject function returning pointer.
+
 2016-03-18  Patrick Palka  <ppalka@gcc.gnu.org>
 
        PR c++/70205
index 1ba3c59c90e99b4ac0cdc0c243c5400f8194e012..22c039bc16dcb6cda1ddb7c04eaf5743da3d2475 100644 (file)
@@ -2872,6 +2872,14 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
          return error_mark_node;
        }
       alloc_fn = OVL_CURRENT (alloc_fn);
+      if (TREE_CODE (alloc_fn) != FUNCTION_DECL
+         || TREE_CODE (TREE_TYPE (alloc_fn)) != FUNCTION_TYPE
+         || !POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (alloc_fn))))
+       {
+         if (complain & tf_error)
+           error ("%qD is not a function returning a pointer", alloc_fn);
+         return error_mark_node;
+       }
       class_addr = build1 (ADDR_EXPR, jclass_node, class_decl);
       alloc_call = cp_build_function_call_nary (alloc_fn, complain,
                                                class_addr, NULL_TREE);
index b56c9bf7351391be7f8c272abebef9f54218fc28..7209e5b49f8e908f0ef9d455f4210efd172d095f 100644 (file)
@@ -1,3 +1,8 @@
+2016-03-18  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/70267
+       * g++.dg/ext/java-3.C: New test.
+
 2016-03-18  Patrick Palka  <ppalka@gcc.gnu.org>
 
        PR c++/70205
diff --git a/gcc/testsuite/g++.dg/ext/java-3.C b/gcc/testsuite/g++.dg/ext/java-3.C
new file mode 100644 (file)
index 0000000..45b2486
--- /dev/null
@@ -0,0 +1,39 @@
+// PR c++/70267
+// { dg-do compile }
+// { dg-options "-O2" }
+
+extern "Java"
+{
+  typedef __java_int jint;
+  namespace java
+  {
+    namespace lang
+    {
+      class Class;
+      class Object;
+      class Throwable {};
+      class Foo;
+    }
+  }
+} 
+
+typedef struct java::lang::Object * jobject;
+typedef struct java::lang::Throwable * jthrowable;
+typedef class  java::lang::Class * jclass;
+
+using java::lang::Foo;
+
+class Foo: public java::lang::Throwable
+{
+  public:static::java::lang::Class class$;
+};
+
+extern "C" Foo _Jv_AllocObject (jclass);
+extern "C" void _Jv_Throw (jthrowable) __attribute__ ((__noreturn__));
+
+void 
+Bar4 (void)
+{
+  Foo * f = new java::lang::Foo;       // { dg-error "is not a function returning a pointer" }
+  throw (f);
+}