OSDN Git Service

* decl.c (start_preparsed_function): Call check_function_type even
authorgiovannibajo <giovannibajo@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 17 Nov 2004 00:17:00 +0000 (00:17 +0000)
committergiovannibajo <giovannibajo@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 17 Nov 2004 00:17:00 +0000 (00:17 +0000)
in templates.
(require_complete_types_for_parms): Skip dependent types.
(check_function_type): Likewise.

* g++.dg/template/incomplete1.C: New test.

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

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/incomplete1.C [new file with mode: 0644]

index a538e5e..ddb1e99 100644 (file)
@@ -1,3 +1,10 @@
+2004-11-16  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
+
+       * decl.c (start_preparsed_function): Call check_function_type even
+       in templates.
+       (require_complete_types_for_parms): Skip dependent types.
+       (check_function_type): Likewise.
+
 2004-11-16  Steven Bosscher  <stevenb@suse.de>
 
        * Make-lang.in (cp/decl.o, cp/search.o): Don't depend on stack.h.
index f82ec87..9baedb4 100644 (file)
@@ -8271,6 +8271,8 @@ require_complete_types_for_parms (tree parms)
 {
   for (; parms; parms = TREE_CHAIN (parms))
     {
+      if (dependent_type_p (TREE_TYPE (parms)))
+       continue;
       if (VOID_TYPE_P (TREE_TYPE (parms)))
         /* grokparms will have already issued an error.  */
         TREE_TYPE (parms) = error_mark_node;
@@ -9840,6 +9842,8 @@ check_function_type (tree decl, tree current_function_parms)
   /* In a function definition, arg types must be complete.  */
   require_complete_types_for_parms (current_function_parms);
 
+  if (dependent_type_p (return_type))
+    return;
   if (!COMPLETE_OR_VOID_TYPE_P (return_type))
     {
       error ("return type %q#T is incomplete", TREE_TYPE (fntype));
@@ -9985,8 +9989,7 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
   /* Make sure the parameter and return types are reasonable.  When
      you declare a function, these types can be incomplete, but they
      must be complete when you define the function.  */
-  if (! processing_template_decl)
-    check_function_type (decl1, current_function_parms);
+  check_function_type (decl1, current_function_parms);
 
   /* Build the return declaration for the function.  */
   restype = TREE_TYPE (fntype);
index 523db7a..8093d75 100644 (file)
@@ -1,3 +1,7 @@
+2004-11-16  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
+
+       * g++.dg/template/incomplete1.C: New test.
+
 2004-11-16  Nick Clifton  <nickc@redhat.com>
 
        Revert patches accidentally commited during checkin of fixes for
diff --git a/gcc/testsuite/g++.dg/template/incomplete1.C b/gcc/testsuite/g++.dg/template/incomplete1.C
new file mode 100644 (file)
index 0000000..e4997ef
--- /dev/null
@@ -0,0 +1,18 @@
+// { dg-do compile }
+// Origin: Ivan Godard <igodard at pacbell dot net>
+// PR c++/17447: Detect parameters of dependent types even in templates
+
+struct B;   // { dg-error "forward declaration" }
+template<typename T> struct A {
+
+    friend A& operator <<(A& a, B b) { return a; } // { dg-error "incomplete" }
+    friend A& operator <<(A& a, T b) { return a; }
+
+    void foo1(B b) {}   // { dg-error "incomplete" }
+    void foo1a(T b) {}
+
+    B foo2(void) {}  // { dg-error "incomplete" }
+    T foo2a(void) {}
+
+    void foo3(B b);
+};