aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2005-01-06 20:21:13 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>2005-01-06 20:21:13 +0000
commit27d6592cc72001b4d4c9b9b4555eecc19d0203e9 (patch)
tree307172f1e13dfc0be1ce45edfd079614f0da9c2e /gcc
parent27916b83f5f371d27f728fcc003fe93b0e44b3cc (diff)
downloadgcc-27d6592cc72001b4d4c9b9b4555eecc19d0203e9.zip
gcc-27d6592cc72001b4d4c9b9b4555eecc19d0203e9.tar.gz
gcc-27d6592cc72001b4d4c9b9b4555eecc19d0203e9.tar.bz2
re PR c++/19244 (Typedef of anonymous class incorrectly handled in member function definition)
PR c++/19244 * class.c (add_implicitly_declared_members): Remove dead code. * decl.c (grokfndecl): Add sfk parameter. Use it do set DECL_CONSTRUCTOR_P. (grokdeclarator): Adjust calls to grokfndecl. * method.c (implicitly_declare_fn): Improve documentation. * parser.c (cp_parser_direct_declarator): Do not consider a function to be a constructor if the containing class was originally anonymous. PR c++/19244 * g++.dg/parser/ctor2.C: New test. From-SVN: r93004
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog12
-rw-r--r--gcc/cp/class.c16
-rw-r--r--gcc/cp/decl.c28
-rw-r--r--gcc/cp/method.c3
-rw-r--r--gcc/cp/parser.c15
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/parse/ctor2.C4
7 files changed, 52 insertions, 31 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 600e945..dee21a9 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,15 @@
+2005-01-06 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/19244
+ * class.c (add_implicitly_declared_members): Remove dead code.
+ * decl.c (grokfndecl): Add sfk parameter. Use it do set
+ DECL_CONSTRUCTOR_P.
+ (grokdeclarator): Adjust calls to grokfndecl.
+ * method.c (implicitly_declare_fn): Improve documentation.
+ * parser.c (cp_parser_direct_declarator): Do not consider a
+ function to be a constructor if the containing class was
+ originally anonymous.
+
2005-01-06 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/17154
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 597ec92..00e6a7e 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -2485,17 +2485,11 @@ add_implicitly_declared_members (tree t,
default_fn = implicitly_declare_fn (sfk_destructor, t, /*const_p=*/0);
check_for_override (default_fn, t);
- /* If we couldn't make it work, then pretend we didn't need it. */
- if (default_fn == void_type_node)
- TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = 0;
- else
- {
- TREE_CHAIN (default_fn) = implicit_fns;
- implicit_fns = default_fn;
-
- if (DECL_VINDEX (default_fn))
- virtual_dtor = default_fn;
- }
+ TREE_CHAIN (default_fn) = implicit_fns;
+ implicit_fns = default_fn;
+
+ if (DECL_VINDEX (default_fn))
+ virtual_dtor = default_fn;
}
else
/* Any non-implicit destructor is non-trivial. */
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 07d8543..e664b1c 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -61,10 +61,6 @@ static int ambi_op_p (enum tree_code);
static int unary_op_p (enum tree_code);
static void push_local_name (tree);
static tree grok_reference_init (tree, tree, tree, tree *);
-static tree grokfndecl (tree, tree, tree, tree, tree, int,
- enum overload_flags, cp_cv_quals,
- tree, int, int, int, int, int, int, tree,
- tree *);
static tree grokvardecl (tree, tree, const cp_decl_specifier_seq *,
int, int, tree);
static void record_unknown_type (tree, const char *);
@@ -5616,6 +5612,8 @@ bad_specifiers (tree object,
CHECK is 1 if we must find this method in CTYPE, 0 if we should
not look, and -1 if we should not call `grokclassfn' at all.
+ SFK is the kind of special function (if any) for the new function.
+
Returns `NULL_TREE' if something goes wrong, after issuing
applicable error messages. */
@@ -5633,6 +5631,7 @@ grokfndecl (tree ctype,
int friendp,
int publicp,
int inlinep,
+ special_function_kind sfk,
int funcdef_flag,
int template_count,
tree in_namespace,
@@ -5843,14 +5842,13 @@ grokfndecl (tree ctype,
if (check < 0)
return decl;
- if (flags == NO_SPECIAL && ctype && constructor_name_p (declarator, ctype))
- DECL_CONSTRUCTOR_P (decl) = 1;
-
- /* Function gets the ugly name, field gets the nice one. This call
- may change the type of the function (because of default
- parameters)! */
if (ctype != NULL_TREE)
- grokclassfn (ctype, decl, flags, quals);
+ {
+ if (sfk == sfk_constructor)
+ DECL_CONSTRUCTOR_P (decl) = 1;
+
+ grokclassfn (ctype, decl, flags, quals);
+ }
decl = check_explicit_specialization (orig_declarator, decl,
template_count,
@@ -7981,6 +7979,7 @@ grokdeclarator (const cp_declarator *declarator,
unqualified_id,
virtualp, flags, quals, raises,
friendp ? -1 : 0, friendp, publicp, inlinep,
+ sfk,
funcdef_flag, template_count, in_namespace, attrlist);
if (decl == NULL_TREE)
return decl;
@@ -8027,8 +8026,9 @@ grokdeclarator (const cp_declarator *declarator,
parms,
unqualified_id,
virtualp, flags, quals, raises,
- friendp ? -1 : 0, friendp, 1, 0, funcdef_flag,
- template_count, in_namespace, attrlist);
+ friendp ? -1 : 0, friendp, 1, 0, sfk,
+ funcdef_flag, template_count, in_namespace,
+ attrlist);
if (decl == NULL_TREE)
return NULL_TREE;
}
@@ -8213,7 +8213,7 @@ grokdeclarator (const cp_declarator *declarator,
decl = grokfndecl (ctype, type, original_name, parms, unqualified_id,
virtualp, flags, quals, raises,
1, friendp,
- publicp, inlinep, funcdef_flag,
+ publicp, inlinep, sfk, funcdef_flag,
template_count, in_namespace, attrlist);
if (decl == NULL_TREE)
return NULL_TREE;
diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index 6716a8f..8cb9e20 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -925,7 +925,8 @@ locate_copy (tree type, void *client_)
/* Implicitly declare the special function indicated by KIND, as a
member of TYPE. For copy constructors and assignment operators,
CONST_P indicates whether these functions should take a const
- reference argument or a non-const reference. */
+ reference argument or a non-const reference. Returns the
+ FUNCTION_DECL for the implicitly declared function. */
tree
implicitly_declare_fn (special_function_kind kind, tree type, bool const_p)
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 4ca03aa..86a96fb 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -11109,11 +11109,16 @@ cp_parser_direct_declarator (cp_parser* parser,
declarator->u.id.sfk = sfk_destructor;
else if (IDENTIFIER_TYPENAME_P (unqualified_name))
declarator->u.id.sfk = sfk_conversion;
- else if (constructor_name_p (unqualified_name,
- class_type)
- || (TREE_CODE (unqualified_name) == TYPE_DECL
- && same_type_p (TREE_TYPE (unqualified_name),
- class_type)))
+ else if (/* There's no way to declare a constructor
+ for an anonymous type, even if the type
+ got a name for linkage purposes. */
+ !TYPE_WAS_ANONYMOUS (class_type)
+ && (constructor_name_p (unqualified_name,
+ class_type)
+ || (TREE_CODE (unqualified_name) == TYPE_DECL
+ && (same_type_p
+ (TREE_TYPE (unqualified_name),
+ class_type)))))
declarator->u.id.sfk = sfk_constructor;
if (ctor_dtor_or_conv_p && declarator->u.id.sfk != sfk_none)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index de33069..d563892 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2005-01-06 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/19244
+ * g++.dg/parser/ctor2.C: New test.
+
2004-01-06 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/17154
diff --git a/gcc/testsuite/g++.dg/parse/ctor2.C b/gcc/testsuite/g++.dg/parse/ctor2.C
new file mode 100644
index 0000000..604fb2f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/ctor2.C
@@ -0,0 +1,4 @@
+// PR c++/19244
+
+typedef struct { void f(); } f;
+void f::f() { }