public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch] [C++0x] Support decltype-specifier as start of nested-name-specifier. (Bug 6709)
@ 2011-01-20 17:08 Adam Butcher
  2011-04-01 22:06 ` Jason Merrill
  0 siblings, 1 reply; 5+ messages in thread
From: Adam Butcher @ 2011-01-20 17:08 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason

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

Hi again,

The attached patch attempts to resolve bug
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=6709  Allowing
decltype(expr) to appear as the start of a nested-name-specifier.

However there is something wrong.  Although it parses fine, the
resulting tree seems to be treated as if it were dependent on a template
parameter.  An additional 'typename' prefix is required to get the
desired behaviour.

Although this seems to work for many scenarios, the resulting tree
seems to be treated as dependent (in the sense of dependent on a
template parameter) even when used outside of a template.  For
instance:

  struct X {};
  struct Y { typedef X Inner; enum { E = 7 }; };
  Y y;
  decltype(y)::Inner x;          // error: 'Inner' does not name a type
  typename decltype(y)::Inner x; // works fine
  int e = decltype(y)::E;        // works fine

I don't think decltype(y) should be deferred in any way, as it should
be known.  Something's obviously missing but I'm not sure what.

Any help appreciated.

Cheers
Adam

[-- Attachment #2: 0001-C-0x-Support-decltype-specifier-as-start-of-nested-n.patch --]
[-- Type: application/octet-stream, Size: 4014 bytes --]

From 70d0074a1da77d587979b0ba05f82f46d4196fd9 Mon Sep 17 00:00:00 2001
From: Adam Butcher <dev.lists@jessamine.co.uk>
Date: Thu, 20 Jan 2011 16:33:34 +0000
Subject: [PATCH] [C++0x] Support decltype-specifier as start of nested-name-specifier.

Although this seems to work for many scenarios, the resulting tree
seems to be treated as dependent (in the sense of dependent on a
template parameter) even when used outside of a template.  For
instance:

  struct X {};
  struct Y { typedef X Inner; enum { E = 7 }; };
  Y y;
  decltype(y)::Inner x;          // error: 'Inner' does not name a type
  typename decltype(y)::Inner x; // works fine
  int e = decltype(y)::E;        // works fine

I don't think decltype(y) should be deferred in any way, as it should
be known.  Something's obviously missing but I'm not sure what.
---
 gcc/cp/parser.c |   37 +++++++++++++++++++++++++++++--------
 1 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index d67dd51..37b49d0 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -4477,6 +4477,7 @@ cp_parser_unqualified_id (cp_parser* parser,
    nested-name-specifier: [C++0x]
      type-name ::
      namespace-name ::
+     decltype-specifier ::
      nested-name-specifier identifier ::
      nested-name-specifier template [opt] simple-template-id ::
 
@@ -4551,6 +4552,9 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
       /* A template-id can start a nested-name-specifier.  */
       else if (token->type == CPP_TEMPLATE_ID)
 	;
+      /* A decltype-specifier can start a nested-name-specifier.  */
+      else if (token->keyword == RID_DECLTYPE)
+	;
       else
 	{
 	  /* If the next token is not an identifier, then it is
@@ -4603,13 +4607,16 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
 	parser->scope = resolve_typename_type (parser->scope,
 					       /*only_current_p=*/false);
       /* Parse the qualifying entity.  */
-      new_scope
-	= cp_parser_qualifying_entity (parser,
-                                       typename_keyword_p,
-                                       template_keyword_p,
-                                       check_dependency_p,
-                                       type_p,
-                                       is_declaration);
+      if (token->keyword == RID_DECLTYPE)
+	new_scope = cp_parser_decltype (parser);
+      else
+        new_scope
+	  = cp_parser_qualifying_entity (parser,
+                                         typename_keyword_p,
+                                         template_keyword_p,
+                                         check_dependency_p,
+                                         type_p,
+                                         is_declaration);
       /* Look for the `::' token.  */
       cp_parser_require (parser, CPP_SCOPE, RT_SCOPE);
 
@@ -12682,7 +12689,8 @@ cp_parser_simple_type_specifier (cp_parser* parser,
   /* Peek at the next token.  */
   token = cp_lexer_peek_token (parser->lexer);
 
-  /* If we're looking at a keyword, things are easy.  */
+  /* If we're looking at a keyword, things are easy.  Except if it's
+     `decltype'. */
   switch (token->keyword)
     {
     case RID_CHAR:
@@ -12750,6 +12758,17 @@ cp_parser_simple_type_specifier (cp_parser* parser,
       break;
 
     case RID_DECLTYPE:
+      /* Decltype could start a nested-name-specifier. */
+      if (cp_parser_nested_name_specifier_opt (parser,
+					       /*typename_keyword_p=*/false,
+					       /*check_dependency_p=*/false,
+					       /*type_p=*/false,
+					       /*is_declaration=*/false)
+	  != NULL_TREE)
+	{
+	  goto check_user_defined;
+	}
+
       /* Parse the `decltype' type.  */
       type = cp_parser_decltype (parser);
 
@@ -12807,6 +12826,8 @@ cp_parser_simple_type_specifier (cp_parser* parser,
       return TYPE_NAME (type);
     }
 
+ check_user_defined:
+
   /* The type-specifier must be a user-defined type.  */
   if (!(flags & CP_PARSER_FLAGS_NO_USER_DEFINED_TYPES))
     {
-- 
1.7.2


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

end of thread, other threads:[~2011-07-25  8:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-20 17:08 [Patch] [C++0x] Support decltype-specifier as start of nested-name-specifier. (Bug 6709) Adam Butcher
2011-04-01 22:06 ` Jason Merrill
2011-07-21 15:59   ` Adam Butcher
2011-07-22 22:17     ` Jason Merrill
2011-07-25  9:20       ` Adam Butcher

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