Clearly my test was inadequate...we need to handle DECLTYPE_TYPE as well
as actual enums and classes.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 9c1e6f92b1b4bd4d30f4d04818900e05c59382bc
Author: Jason Merrill <ja...@redhat.com>
Date: Sat Jul 23 14:21:48 2011 -0400
PR c++/49823
* parser.c (cp_parser_qualifying_entity): Handle templates.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index dc54dc2..4e7d905 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -4638,7 +4638,9 @@ cp_parser_qualifying_entity (cp_parser *parser,
cp_parser_simulate_error (parser);
return error_mark_node;
}
- return TYPE_NAME (scope);
+ if (TYPE_NAME (scope))
+ scope = TYPE_NAME (scope);
+ return scope;
}
/* Before we try to parse the class-name, we must save away the
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype21.C b/gcc/testsuite/g++.dg/cpp0x/decltype21.C
index ee73bfb..7337256 100644
--- a/gcc/testsuite/g++.dg/cpp0x/decltype21.C
+++ b/gcc/testsuite/g++.dg/cpp0x/decltype21.C
@@ -10,6 +10,22 @@ struct c : decltype(make<p>()) {};
decltype(make<p>())::t t;
+// PR c++/49823
+
+template < typename T >
+auto f( const T &x )
+ -> typename decltype( x )::type; // ICE on here
+
+template < typename T >
+typename decltype( T{} )::type // ICE on here
+f( T );
+
+template < typename T >
+void f( T x )
+{ typename decltype( x )::type t; } // ICE on here
+
+// Negative tests
+
int f();
decltype(f())::t t2; // { dg-error "not a class" }