OSDN Git Service

gcc/cp/
authorhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 27 Mar 2009 13:17:37 +0000 (13:17 +0000)
committerhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 27 Mar 2009 13:17:37 +0000 (13:17 +0000)
2009-03-27  Simon Martin  <simartin@users.sourceforge.net>

PR c++/37647
* decl.c (grokdeclarator): Reject [con|de]stuctors in a non-class
scope.

gcc/testsuite/

2009-03-27  Simon Martin  <simartin@users.sourceforge.net>

PR c++/37647
* g++.dg/parse/ctor9.C: New test.

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

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

index 3b91d68..d120594 100644 (file)
@@ -1,5 +1,11 @@
 2009-03-27  Simon Martin  <simartin@users.sourceforge.net>
 
+       PR c++/37647
+       * decl.c (grokdeclarator): Reject [con|de]stuctors in a non-class
+       scope.
+
+2009-03-27  Simon Martin  <simartin@users.sourceforge.net>
+
        PR c++/29727
        * decl.c (check_array_designated_initializer): Handle error_mark_node.
 
index 2a89ef4..b16ae26 100644 (file)
@@ -9346,6 +9346,14 @@ grokdeclarator (const cp_declarator *declarator,
                error ("virtual non-class function %qs", name);
                virtualp = 0;
              }
+           else if (sfk == sfk_constructor
+                    || sfk == sfk_destructor)
+             {
+               error (funcdef_flag
+                      ? "%qs defined in a non-class scope"
+                      : "%qs declared in a non-class scope", name);
+               sfk = sfk_none;
+             }
          }
        else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
                 && !NEW_DELETE_OPNAME_P (original_name))
index 950397f..82fc8ab 100644 (file)
@@ -1,5 +1,10 @@
 2009-03-27  Simon Martin  <simartin@users.sourceforge.net>
 
+       PR c++/37647
+       * g++.dg/parse/ctor9.C: New test.
+
+2009-03-27  Simon Martin  <simartin@users.sourceforge.net>
+
        PR c++/29727
        * g++.dg/init/error2.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/parse/ctor9.C b/gcc/testsuite/g++.dg/parse/ctor9.C
new file mode 100644 (file)
index 0000000..b80f728
--- /dev/null
@@ -0,0 +1,7 @@
+/* PR c++/37647 */
+/* { dg-do "compile" } */
+
+struct A
+{
+  A() { void A(); } /* { dg-error "return type specification for constructor invalid|non-class scope" } */
+};