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

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