This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++ PATCH] Don't ICE on invalid decltype uses (PR c++/34271)


On Tue, Dec 04, 2007 at 04:20:45PM -0500, Doug Gregor wrote:
> On 12/4/07, Jakub Jelinek <jakub@redhat.com> wrote:
> > As shown on the first testcase (and second as well if the parser.c
> > hunk isn't applied), non-dependent SCOPE_REFs can make it into
> > finish_decltype_type, which will ICE on them.  On decltype9.C
> > the SCOPE_REF is created from VAR_DECL in finish_id_expression:
> >               if (processing_template_decl && TYPE_P (scope))
> >                 r = build_qualified_name (TREE_TYPE (r),
> >                                           scope, decl,
> >                                           template_p);
> > The patch below cures this by deferring even non-dependent SCOPE_REFs
> > till instantiation, at which point either diagnostics will be issued
> > or they will materialize to something else, but other option is just handle
> > SCOPE_REF in finish_decltype_type by issuing an error on it like we do for
> > types already.
> 
> I'd rather just handle SCOPE_REF in finish_decltype_type and print the
> error at that point. As a general rule, we should diagnose whatever we
> can when parsing the template. Sooner or later, we're going to have to
> if we want to properly support C++0x concepts.

Ok, here is the alternative patch, regtested on x86_64-linux:

2007-12-04  Jakub Jelinek  <jakub@redhat.com>

	PR c++/34271
	* semantics.c (finish_decltype_type): For SCOPE_REF issue an
	error instead of assertion failure.
	* parser.c (cp_parser_decltype): If closing paren is not found,
	return error_mark_node.

	* g++.dg/cpp0x/decltype9.C: New test.
	* g++.dg/cpp0x/decltype10.C: New test.

--- gcc/cp/parser.c.jj	2007-12-04 20:33:17.000000000 +0100
+++ gcc/cp/parser.c	2007-12-04 20:44:19.000000000 +0100
@@ -8602,8 +8602,11 @@ cp_parser_decltype (cp_parser *parser)
   
   /* Parse to the closing `)'.  */
   if (!cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
-    cp_parser_skip_to_closing_parenthesis (parser, true, false,
-					   /*consume_paren=*/true);
+    {
+      cp_parser_skip_to_closing_parenthesis (parser, true, false,
+					     /*consume_paren=*/true);
+      return error_mark_node;
+    }
 
   return finish_decltype_type (expr, id_expression_or_member_access_p);
 }
--- gcc/cp/semantics.c.jj	2007-12-04 20:33:17.000000000 +0100
+++ gcc/cp/semantics.c	2007-12-04 22:30:20.000000000 +0100
@@ -4164,7 +4164,8 @@ finish_decltype_type (tree expr, bool id
           break;
 
         default:
-          gcc_assert (TYPE_P (expr) || DECL_P (expr));
+	  gcc_assert (TYPE_P (expr) || DECL_P (expr)
+		      || TREE_CODE (expr) == SCOPE_REF);
           error ("argument to decltype must be an expression");
           return error_mark_node;
         }
--- gcc/testsuite/g++.dg/cpp0x/decltype9.C.jj	2007-12-04 20:44:19.000000000 +0100
+++ gcc/testsuite/g++.dg/cpp0x/decltype9.C	2007-12-04 22:30:49.000000000 +0100
@@ -0,0 +1,10 @@
+// PR c++/34271
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+
+template<int> struct A
+{
+  static int i;
+};
+
+template<int N> int A<N>::i(decltype (A::i));	// { dg-error "member function|must be an expression" }
--- gcc/testsuite/g++.dg/cpp0x/decltype10.C.jj	2007-12-04 20:44:19.000000000 +0100
+++ gcc/testsuite/g++.dg/cpp0x/decltype10.C	2007-12-04 20:44:19.000000000 +0100
@@ -0,0 +1,10 @@
+// PR c++/34271
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+
+template<int> struct A
+{
+  static int i;
+};
+
+template<int N> int A<N>::i(decltype (A::i;	// { dg-error "expected primary-expression before" }


	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]