public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] for c++/52465
@ 2012-03-08 21:35 Fabien Chêne
  2012-03-12 12:36 ` Dodji Seketeli
  2012-03-29 14:11 ` Jason Merrill
  0 siblings, 2 replies; 10+ messages in thread
From: Fabien Chêne @ 2012-03-08 21:35 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 756 bytes --]

Hi,

In the end, I think we need again to strip some USING_DECLs in a
couple of places. Tested x86_64-unknown-linux-gnu. OK to commit (for
whatever appropriate) ?

gcc/testsuite/ChangeLog

2012-03-08  Fabien Chêne  <fabien@gcc.gnu.org>

        PR c++/52465
	* g++.dg/lookup/using52.C: New.

gcc/cp/ChangeLog

2012-03-08  Fabien Chêne  <fabien@gcc.gnu.org>

        PR c++/52465
	* decl.c (grokdeclarator): Call strip_using_decl.
	* parser.c (cp_parser_class_name): Call strip_using_decl and
	perform some checks on the target decl.
	* 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: pr52465.patch --]
[-- Type: application/octet-stream, Size: 4096 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/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 184891)
+++ gcc/cp/decl.c	(working copy)
@@ -8686,6 +8686,9 @@ grokdeclarator (const cp_declarator *dec
       type = NULL_TREE;
       type_was_error_mark_node = true;
     }
+
+  type = strip_using_decl (type);
+
   /* If the entire declaration is itself tagged as deprecated then
      suppress reports of deprecated items.  */
   if (type && TREE_DEPRECATED (type)
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 184891)
+++ gcc/cp/parser.c	(working copy)
@@ -1,6 +1,6 @@
 /* C++ Parser.
    Copyright (C) 2000, 2001, 2002, 2003, 2004,
-   2005, 2007, 2008, 2009, 2010, 2011  Free Software Foundation, Inc.
+   2005, 2007, 2008, 2009, 2010, 2011, 2012  Free Software Foundation, Inc.
    Written by Mark Mitchell <mark@codesourcery.com>.
 
    This file is part of GCC.
@@ -17734,6 +17734,7 @@ cp_parser_class_name (cp_parser *parser,
 		      bool is_declaration)
 {
   tree decl;
+  tree target_decl;
   tree scope;
   bool typename_p;
   cp_token *token;
@@ -17835,6 +17836,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
@@ -17854,14 +17857,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)
Index: gcc/cp/name-lookup.c
===================================================================
--- gcc/cp/name-lookup.c	(revision 184891)
+++ 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.  */

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [C++ Patch] for c++/52465
  2012-03-08 21:35 [C++ Patch] for c++/52465 Fabien Chêne
@ 2012-03-12 12:36 ` Dodji Seketeli
  2012-03-12 16:19   ` Fabien Chêne
  2012-03-29 14:11 ` Jason Merrill
  1 sibling, 1 reply; 10+ messages in thread
From: Dodji Seketeli @ 2012-03-12 12:36 UTC (permalink / raw)
  To: Fabien Chêne; +Cc: Jason Merrill, GCC Patches

Hello Fabien,

Fabien Chêne <fabien.chene@gmail.com> a écrit:

[...]

> Index: gcc/cp/decl.c
> ===================================================================
> --- gcc/cp/decl.c	(revision 184891)
> +++ gcc/cp/decl.c	(working copy)
> @@ -8686,6 +8686,9 @@ grokdeclarator (const cp_declarator *dec
>        type = NULL_TREE;
>        type_was_error_mark_node = true;
>      }
> +
> +  type = strip_using_decl (type);
> +

I am a little bit curious as to why this change is necessary.  It seems
to me that the test case of your patch would pass even without this
change, wouldn't it?

Thanks.

-- 
		Dodji

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [C++ Patch] for c++/52465
  2012-03-12 12:36 ` Dodji Seketeli
@ 2012-03-12 16:19   ` Fabien Chêne
  2012-04-07 15:38     ` Fabien Chêne
  0 siblings, 1 reply; 10+ messages in thread
From: Fabien Chêne @ 2012-03-12 16:19 UTC (permalink / raw)
  To: GCC Patches; +Cc: Jason Merrill

Salut Dodji,

2012/3/12 Dodji Seketeli <dodji@seketeli.org>:
[...]
>> Index: gcc/cp/decl.c
>> ===================================================================
>> --- gcc/cp/decl.c     (revision 184891)
>> +++ gcc/cp/decl.c     (working copy)
>> @@ -8686,6 +8686,9 @@ grokdeclarator (const cp_declarator *dec
>>        type = NULL_TREE;
>>        type_was_error_mark_node = true;
>>      }
>> +
>> +  type = strip_using_decl (type);
>> +
>
> I am a little bit curious as to why this change is necessary.  It seems
> to me that the test case of your patch would pass even without this
> change, wouldn't it?

Yes, this testcase would pass, but an existing testcase wouldn't. I
don't remeber which one, but I think it was related to using
declarations that refer to a typedef.

struct A { typedef int T; };
stuct B : A { using B::T; };

-- 
Fabien

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [C++ Patch] for c++/52465
  2012-03-08 21:35 [C++ Patch] for c++/52465 Fabien Chêne
  2012-03-12 12:36 ` Dodji Seketeli
@ 2012-03-29 14:11 ` Jason Merrill
  2012-04-07 15:37   ` Fabien Chêne
  1 sibling, 1 reply; 10+ messages in thread
From: Jason Merrill @ 2012-03-29 14:11 UTC (permalink / raw)
  To: Fabien Chêne; +Cc: GCC Patches

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.

Jason

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [C++ Patch] for c++/52465
  2012-03-29 14:11 ` Jason Merrill
@ 2012-04-07 15:37   ` Fabien Chêne
  2012-04-07 21:14     ` Jason Merrill
  0 siblings, 1 reply; 10+ messages in thread
From: Fabien Chêne @ 2012-04-07 15:37 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches

[-- 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.  */

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [C++ Patch] for c++/52465
  2012-03-12 16:19   ` Fabien Chêne
@ 2012-04-07 15:38     ` Fabien Chêne
  0 siblings, 0 replies; 10+ messages in thread
From: Fabien Chêne @ 2012-04-07 15:38 UTC (permalink / raw)
  To: GCC Patches, Dodji Seketeli; +Cc: Jason Merrill

2012/3/12 Fabien Chêne <fabien.chene@gmail.com>:
> Salut Dodji,
>
> 2012/3/12 Dodji Seketeli <dodji@seketeli.org>:
> [...]
>>> Index: gcc/cp/decl.c
>>> ===================================================================
>>> --- gcc/cp/decl.c     (revision 184891)
>>> +++ gcc/cp/decl.c     (working copy)
>>> @@ -8686,6 +8686,9 @@ grokdeclarator (const cp_declarator *dec
>>>        type = NULL_TREE;
>>>        type_was_error_mark_node = true;
>>>      }
>>> +
>>> +  type = strip_using_decl (type);
>>> +
>>
>> I am a little bit curious as to why this change is necessary.  It seems
>> to me that the test case of your patch would pass even without this
>> change, wouldn't it?
>
> Yes, this testcase would pass, but an existing testcase wouldn't. I
> don't remeber which one, but I think it was related to using
> declarations that refer to a typedef.
>
> struct A { typedef int T; };
> stuct B : A { using B::T; };

More precisely, the testcase which was failing is g++.other/using5.C.

-- 
Fabien

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [C++ Patch] for c++/52465
  2012-04-07 15:37   ` Fabien Chêne
@ 2012-04-07 21:14     ` Jason Merrill
  2012-04-10 20:23       ` Fabien Chêne
  0 siblings, 1 reply; 10+ messages in thread
From: Jason Merrill @ 2012-04-07 21:14 UTC (permalink / raw)
  To: Fabien Chêne; +Cc: GCC Patches

On 04/07/2012 11:37 AM, Fabien Chêne wrote:
> Perhaps it is more correct like that, in cp_parser_set_decl_spec_type ?

Even that seems late.  Why not just return the target decl from 
cp_parser_class_name?

Jason

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [C++ Patch] for c++/52465
  2012-04-07 21:14     ` Jason Merrill
@ 2012-04-10 20:23       ` Fabien Chêne
  2012-04-11  2:17         ` Jason Merrill
  0 siblings, 1 reply; 10+ messages in thread
From: Fabien Chêne @ 2012-04-10 20:23 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 1096 bytes --]

2012/4/7 Jason Merrill <jason@redhat.com>:
> On 04/07/2012 11:37 AM, Fabien Chêne wrote:
>>
>> Perhaps it is more correct like that, in cp_parser_set_decl_spec_type ?
>
> Even that seems late.  Why not just return the target decl from
> cp_parser_class_name?

Ah yes, that's slightly better.
(I've kept the NULL check in strip_using_decl, it seems safer to me.
Just tell me if you prefer not)
Tested x86_64-unkown-linux-gnu. OK for trunk and 4.7 ?

gcc/testsuite/ChangeLog

2012-03-08  Fabien Chêne  <fabien@gcc.gnu.org>

       PR c++/52465
       * g++.dg/lookup/using52.C: New.

gcc/cp/ChangeLog

2012-03-08  Fabien Chêne  <fabien@gcc.gnu.org>

       PR c++/52465
       * decl.c (grokdeclarator): Call strip_using_decl.
       * parser.c (cp_parser_class_name): Call strip_using_decl and
       perform some checks on the target decl.
       * 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_3.patch --]
[-- Type: application/octet-stream, Size: 2308 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)
@@ -17845,6 +17845,8 @@ cp_parser_class_name (cp_parser *parser,
 	decl = TYPE_NAME (decl);
     }
 
+  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
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.  */

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [C++ Patch] for c++/52465
  2012-04-10 20:23       ` Fabien Chêne
@ 2012-04-11  2:17         ` Jason Merrill
  2012-04-12  8:20           ` Fabien Chêne
  0 siblings, 1 reply; 10+ messages in thread
From: Jason Merrill @ 2012-04-11  2:17 UTC (permalink / raw)
  To: Fabien Chêne; +Cc: GCC Patches

On 04/10/2012 04:23 PM, Fabien Chêne wrote:
> Ah yes, that's slightly better.
> (I've kept the NULL check in strip_using_decl, it seems safer to me.
> Just tell me if you prefer not)
> Tested x86_64-unkown-linux-gnu. OK for trunk and 4.7 ?
>
> 2012-03-08  Fabien Chêne<fabien@gcc.gnu.org>
>
>         PR c++/52465
>         * decl.c (grokdeclarator): Call strip_using_decl.
>         * parser.c (cp_parser_class_name): Call strip_using_decl and
>         perform some checks on the target decl.
>         * 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.

Your ChangeLog needs to be adjusted.  :)

The patch is OK, thanks!

Jason

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [C++ Patch] for c++/52465
  2012-04-11  2:17         ` Jason Merrill
@ 2012-04-12  8:20           ` Fabien Chêne
  0 siblings, 0 replies; 10+ messages in thread
From: Fabien Chêne @ 2012-04-12  8:20 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches

2012/4/11 Jason Merrill <jason@redhat.com>:
[...]
> Your ChangeLog needs to be adjusted.  :)

I did write an updated ChangeLog, but I pasted here the wrong one...
I committed it to trunk yesterday, hopefully with the correct
ChangeLog . I'll be backporting it to 4.7 after a relaxing weekend :-)

-- 
Fabien

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-04-12  8:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-08 21:35 [C++ Patch] for c++/52465 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
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

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).