Simon Martin - [PATCH] Fix PR c++/29077: Incorrect error message for destructor in wron (original) (raw)
This is the mail archive of the gcc-patches@gcc.gnu.orgmailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
- From: Simon Martin
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 22 Feb 2007 07:48:35 +0100
- Subject: [PATCH] Fix PR c++/29077: Incorrect error message for destructor in wrong namespace
Hi all.
The following invalid code snippet
=== cut here ===
class c { c(); };
namespace m { c::c() { } }
=== cut here ===
currently gives this error message: "definition of âvoid c::c()â is not in namespace enclosing âcâ", where "void c::c()" should obviously be "c::~c()"...
The problem is that 'grokfndecl' does not setup the decl according to the value of sfk, and 'check_class_member_definition_namespace' sees a method named "c" instead of a destructor.
The attached patch fixes this by properly setting DECL_CONSTRUCTOR_P and DECL_DESTRUCTOR_P if necessary at the beginning of 'grokfndecl'.
This has been successfully regtested on i686-pc-linux-gnu. Is it OK?
Thanks in advance, Simon
:ADDPATCH c++:
2007-02-21 Simon Martin simartin@users.sourceforge.net
PR c++/29077
* decl.c (grokfndecl): Properly setup decl if it is a constructor or a
destructor.
Index: gcc/cp/decl.c
--- gcc/cp/decl.c (revision 122202) +++ gcc/cp/decl.c (working copy) @@ -5978,6 +5978,20 @@ grokfndecl (tree ctype, if (TYPE_VOLATILE (type)) TREE_THIS_VOLATILE (decl) = 1; + /* Setup decl according to sfk. */ + switch (sfk) + { + case sfk_constructor: + case sfk_copy_constructor: + DECL_CONSTRUCTOR_P (decl) = 1; + break; + case sfk_destructor: + DECL_DESTRUCTOR_P (decl) = 1; + break; + default: + break; + } + if (friendp && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR) { @@ -6165,12 +6179,7 @@ grokfndecl (tree ctype, return decl; if (ctype != NULL_TREE) - { - if (sfk == sfk_constructor) - DECL_CONSTRUCTOR_P (decl) = 1;
grokclassfn (ctype, decl, flags);
- }
- grokclassfn (ctype, decl, flags);
decl = check_explicit_specialization (orig_declarator, decl, template_count,
2007-02-21 Simon Martin simartin@users.sourceforge.net
PR c++/29077
* g++.dg/parse/constructor3.C: New test.
/* PR c++/29077 / / { dg-do "compile" } */
class c { c(); c(const c&); ~c(); };
namespace m { c::c() {} /* { dg-error "c::c" } / c::c(const c&) {} / { dg-error "c::c" } / c::~c() {} / { dg-error "c::~c" } */ }
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |