From: "Fabien Chêne" <fabien.chene@gmail.com>
To: Jason Merrill <jason@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [C++ Patch] for c++/52465
Date: Sat, 07 Apr 2012 15:37:00 -0000 [thread overview]
Message-ID: <CAFH4-djHAKYxEwiYbOjzkkD2N+R3fGeVGoiD846o_hbGha3zwQ@mail.gmail.com> (raw)
In-Reply-To: <4F746D6F.1040705@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1313 bytes --]
2012/3/29 Jason Merrill <jason@redhat.com>:
> On 03/08/2012 04:34 PM, Fabien Chêne wrote:
>>
>> * decl.c (grokdeclarator): Call strip_using_decl.
>
>
> I would think we ought to be stripping USING_DECLs at a lower level, when we
> first look up the name in the parser. They shouldn't make it as far as
> grokdeclarator.
Perhaps it is more correct like that, in cp_parser_set_decl_spec_type ?
Bootstrapped/tested x86_64-unknown-linux-gnu.
gcc/testsuite/ChangeLog
2012-04-07 Fabien Chêne <fabien@gcc.gnu.org>
PR c++/52465
* g++.dg/lookup/using52.C: New.
gcc/cp/ChangeLog
2012-04-07 Fabien Chêne <fabien@gcc.gnu.org>
PR c++/52465
* parser.c (cp_parser_class_name): Call strip_using_decl and
perform some checks on the target decl.
(cp_parser_set_decl_spec_type): Change its prototype so that the
second argument be modifiable, and strip using declarations of
that argument.
(cp_parser_type_specifier): Adjust the calls to
cp_parser_set_decl_spec_type.
(cp_parser_simple_type_specifier): Likewise.
* name-lookup.c (strip_using_decl): Returns NULL_TREE if the decl
to be stripped is NULL_TREE.
(qualify_lookup): Call strip_using_decl and perform some checks on
the target decl.
--
Fabien
[-- Attachment #2: 52465_2.patch --]
[-- Type: application/octet-stream, Size: 7421 bytes --]
Index: gcc/testsuite/g++.dg/lookup/using52.C
===================================================================
--- gcc/testsuite/g++.dg/lookup/using52.C (revision 0)
+++ gcc/testsuite/g++.dg/lookup/using52.C (revision 0)
@@ -0,0 +1,16 @@
+// { dg-do compile }
+// PR c++/52645
+
+class A
+{
+protected:
+ struct B {};
+};
+
+class C : A
+{
+protected:
+ using A::B;
+
+ struct D : public B {};
+};
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c (revision 186167)
+++ gcc/cp/parser.c (working copy)
@@ -2220,7 +2220,7 @@ static bool cp_parser_declares_only_clas
static void cp_parser_set_storage_class
(cp_parser *, cp_decl_specifier_seq *, enum rid, location_t);
static void cp_parser_set_decl_spec_type
- (cp_decl_specifier_seq *, tree, location_t, bool);
+ (cp_decl_specifier_seq *, tree *, location_t, bool);
static bool cp_parser_friend_p
(const cp_decl_specifier_seq *);
static void cp_parser_required_error
@@ -13335,7 +13335,7 @@ cp_parser_type_specifier (cp_parser* par
*declares_class_or_enum = 2;
if (decl_specs)
cp_parser_set_decl_spec_type (decl_specs,
- type_spec,
+ &type_spec,
token->location,
/*type_definition_p=*/true);
return type_spec;
@@ -13364,7 +13364,7 @@ cp_parser_type_specifier (cp_parser* par
*declares_class_or_enum = 2;
if (decl_specs)
cp_parser_set_decl_spec_type (decl_specs,
- type_spec,
+ &type_spec,
token->location,
/*type_definition_p=*/true);
return type_spec;
@@ -13386,7 +13386,7 @@ cp_parser_type_specifier (cp_parser* par
is_declaration));
if (decl_specs)
cp_parser_set_decl_spec_type (decl_specs,
- type_spec,
+ &type_spec,
token->location,
/*type_definition_p=*/false);
return type_spec;
@@ -13579,7 +13579,7 @@ cp_parser_simple_type_specifier (cp_pars
type = finish_typeof (type);
if (decl_specs)
- cp_parser_set_decl_spec_type (decl_specs, type,
+ cp_parser_set_decl_spec_type (decl_specs, &type,
token->location,
/*type_definition_p=*/false);
@@ -13588,7 +13588,7 @@ cp_parser_simple_type_specifier (cp_pars
case RID_UNDERLYING_TYPE:
type = cp_parser_trait_expr (parser, RID_UNDERLYING_TYPE);
if (decl_specs)
- cp_parser_set_decl_spec_type (decl_specs, type,
+ cp_parser_set_decl_spec_type (decl_specs, &type,
token->location,
/*type_definition_p=*/false);
@@ -13598,7 +13598,7 @@ cp_parser_simple_type_specifier (cp_pars
case RID_DIRECT_BASES:
type = cp_parser_trait_expr (parser, token->keyword);
if (decl_specs)
- cp_parser_set_decl_spec_type (decl_specs, type,
+ cp_parser_set_decl_spec_type (decl_specs, &type,
token->location,
/*type_definition_p=*/false);
return type;
@@ -13613,7 +13613,7 @@ cp_parser_simple_type_specifier (cp_pars
{
type = token->u.value;
if (decl_specs)
- cp_parser_set_decl_spec_type (decl_specs, type,
+ cp_parser_set_decl_spec_type (decl_specs, &type,
token->location,
/*type_definition_p=*/false);
cp_lexer_consume_token (parser->lexer);
@@ -13630,7 +13630,7 @@ cp_parser_simple_type_specifier (cp_pars
&& token->keyword != RID_SHORT
&& token->keyword != RID_LONG))
cp_parser_set_decl_spec_type (decl_specs,
- type,
+ &type,
token->location,
/*type_definition_p=*/false);
if (decl_specs)
@@ -13705,7 +13705,7 @@ cp_parser_simple_type_specifier (cp_pars
&& !cp_parser_parse_definitely (parser))
type = NULL_TREE;
if (type && decl_specs)
- cp_parser_set_decl_spec_type (decl_specs, type,
+ cp_parser_set_decl_spec_type (decl_specs, &type,
token->location,
/*type_definition_p=*/false);
}
@@ -17744,6 +17744,7 @@ cp_parser_class_name (cp_parser *parser,
bool is_declaration)
{
tree decl;
+ tree target_decl;
tree scope;
bool typename_p;
cp_token *token;
@@ -17845,6 +17846,8 @@ cp_parser_class_name (cp_parser *parser,
decl = TYPE_NAME (decl);
}
+ target_decl = strip_using_decl (decl);
+
/* Check to see that it is really the name of a class. */
if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
&& TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
@@ -17864,14 +17867,14 @@ cp_parser_class_name (cp_parser *parser,
if (decl != error_mark_node)
decl = TYPE_NAME (decl);
}
- else if (TREE_CODE (decl) != TYPE_DECL
- || TREE_TYPE (decl) == error_mark_node
- || !MAYBE_CLASS_TYPE_P (TREE_TYPE (decl))
+ else if (TREE_CODE (target_decl) != TYPE_DECL
+ || TREE_TYPE (target_decl) == error_mark_node
+ || !MAYBE_CLASS_TYPE_P (TREE_TYPE (target_decl))
/* In Objective-C 2.0, a classname followed by '.' starts a
dot-syntax expression, and it's not a type-name. */
|| (c_dialect_objc ()
&& cp_lexer_peek_token (parser->lexer)->type == CPP_DOT
- && objc_is_class_name (decl)))
+ && objc_is_class_name (target_decl)))
decl = error_mark_node;
if (decl == error_mark_node)
@@ -22063,15 +22066,17 @@ cp_parser_set_storage_class (cp_parser *
decl_specs->conflicting_specifiers_p = true;
}
-/* Update the DECL_SPECS to reflect the TYPE_SPEC. If TYPE_DEFINITION_P
+/* Update the DECL_SPECS to reflect the TYPE_SPECIFIER. If TYPE_DEFINITION_P
is true, the type is a class or enum definition. */
static void
cp_parser_set_decl_spec_type (cp_decl_specifier_seq *decl_specs,
- tree type_spec,
+ tree *type_specifier,
location_t location,
bool type_definition_p)
{
+ tree type_spec = strip_using_decl (*type_specifier);
+ *type_specifier = type_spec;
decl_specs->any_specifiers_p = true;
/* If the user tries to redeclare bool, char16_t, char32_t, or wchar_t
Index: gcc/cp/name-lookup.c
===================================================================
--- gcc/cp/name-lookup.c (revision 186167)
+++ gcc/cp/name-lookup.c (working copy)
@@ -1,5 +1,5 @@
/* Definitions for C++ name lookup routines.
- Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+ Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
Free Software Foundation, Inc.
Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
@@ -400,6 +400,9 @@ pop_binding (tree id, tree decl)
tree
strip_using_decl (tree decl)
{
+ if (decl == NULL_TREE)
+ return NULL_TREE;
+
while (TREE_CODE (decl) == USING_DECL && !DECL_DEPENDENT_P (decl))
decl = USING_DECL_DECLS (decl);
return decl;
@@ -4115,9 +4118,13 @@ qualify_lookup (tree val, int flags)
return false;
if ((flags & LOOKUP_PREFER_NAMESPACES) && TREE_CODE (val) == NAMESPACE_DECL)
return true;
- if ((flags & LOOKUP_PREFER_TYPES)
- && (TREE_CODE (val) == TYPE_DECL || TREE_CODE (val) == TEMPLATE_DECL))
- return true;
+ if (flags & LOOKUP_PREFER_TYPES)
+ {
+ tree target_val = strip_using_decl (val);
+ if (TREE_CODE (target_val) == TYPE_DECL
+ || TREE_CODE (target_val) == TEMPLATE_DECL)
+ return true;
+ }
if (flags & (LOOKUP_PREFER_NAMESPACES | LOOKUP_PREFER_TYPES))
return false;
/* Look through lambda things that we shouldn't be able to see. */
next prev parent reply other threads:[~2012-04-07 15:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-08 21:35 Fabien Chêne
2012-03-12 12:36 ` Dodji Seketeli
2012-03-12 16:19 ` Fabien Chêne
2012-04-07 15:38 ` Fabien Chêne
2012-03-29 14:11 ` Jason Merrill
2012-04-07 15:37 ` Fabien Chêne [this message]
2012-04-07 21:14 ` Jason Merrill
2012-04-10 20:23 ` Fabien Chêne
2012-04-11 2:17 ` Jason Merrill
2012-04-12 8:20 ` Fabien Chêne
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAFH4-djHAKYxEwiYbOjzkkD2N+R3fGeVGoiD846o_hbGha3zwQ@mail.gmail.com \
--to=fabien.chene@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).