re PR c++/38794 (Function body accepted in typedef)
authorJakub Jelinek <jakub@redhat.com>
Mon, 12 Jan 2009 15:43:22 +0000 (16:43 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 12 Jan 2009 15:43:22 +0000 (16:43 +0100)
PR c++/38794
* decl.c (start_function): If grokdeclarator hasn't returned
FUNCTION_DECL nor error_mark_node, issue diagnostics.

* g++.dg/parse/typedef9.C: New test.

From-SVN: r143292

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

index 7b0c39f00b2243f7262536ab964dbcc9df53c1bc..de7d1ab06846a401375155013eb531c69e3dcf99 100644 (file)
@@ -1,3 +1,9 @@
+2009-01-12  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/38794
+       * decl.c (start_function): If grokdeclarator hasn't returned
+       FUNCTION_DECL nor error_mark_node, issue diagnostics.
+
 2009-01-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/36254
index 2e19fb3c8d3a54a3ccdf5c6e21bec67790dce2b1..c6ed22d6e7435f69df8faca9dc1ff78ae3368a3b 100644 (file)
@@ -1,6 +1,6 @@
 /* Process declarations and variables for C++ compiler.
    Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
    Free Software Foundation, Inc.
    Contributed by Michael Tiemann (tiemann@cygnus.com)
 
@@ -11774,10 +11774,15 @@ start_function (cp_decl_specifier_seq *declspecs,
   tree decl1;
 
   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs);
+  if (decl1 == error_mark_node)
+    return 0;
   /* If the declarator is not suitable for a function definition,
      cause a syntax error.  */
   if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL)
-    return 0;
+    {
+      error ("invalid function declaration");
+      return 0;
+    }
 
   if (DECL_MAIN_P (decl1))
     /* main must return int.  grokfndecl should have corrected it
index 260504aa86508054fb2119d3e021b51144e52ea9..28df5ac74e560d8eb31051474eca82533a088712 100644 (file)
@@ -1,5 +1,8 @@
 2009-01-12  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/38794
+       * g++.dg/parse/typedef9.C: New test.
+
        PR tree-optimization/38807
        * gcc.c-torture/compile/pr38807.c: New test.
 
diff --git a/gcc/testsuite/g++.dg/parse/typedef9.C b/gcc/testsuite/g++.dg/parse/typedef9.C
new file mode 100644 (file)
index 0000000..7788f78
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/38794
+// { dg-do compile }
+
+typedef void foo () {} // { dg-error "invalid function declaration" }
+struct S
+{
+  typedef int bar (void) { return 0; } // { dg-error "invalid member function declaration" }
+};