public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/9154] [3.4 regression] poor error message for ">>" vs. "> >" for nested template args
       [not found] <20030103012600.9154.tilps@hotmail.com>
@ 2003-06-20 13:56 ` giovannibajo at libero dot it
  2003-06-20 14:13 ` bangerth at dealii dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: giovannibajo at libero dot it @ 2003-06-20 13:56 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9154



------- Additional Comments From giovannibajo at libero dot it  2003-06-20 13:56 -------
Patch submitted:
http://gcc.gnu.org/ml/gcc-patches/2003-06/msg02389.html


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

* [Bug c++/9154] [3.4 regression] poor error message for ">>" vs. "> >" for nested template args
       [not found] <20030103012600.9154.tilps@hotmail.com>
  2003-06-20 13:56 ` [Bug c++/9154] [3.4 regression] poor error message for ">>" vs. "> >" for nested template args giovannibajo at libero dot it
@ 2003-06-20 14:13 ` bangerth at dealii dot org
  2003-07-15 15:12 ` giovannibajo at libero dot it
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: bangerth at dealii dot org @ 2003-06-20 14:13 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9154



------- Additional Comments From bangerth at dealii dot org  2003-06-20 14:13 -------
Giovanni, I don't have time to check with your patch at present, but
how does the patch act if presented with code like

  template <int> struct A{};
  template <typename> struct B {};

  B<A< 1>>2 > > b;

or, even weirder (needs two tokens lookahead):
  const int x = 0;
  B<A< 1>>x > > c;

W.


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

* [Bug c++/9154] [3.4 regression] poor error message for ">>" vs. "> >" for nested template args
       [not found] <20030103012600.9154.tilps@hotmail.com>
  2003-06-20 13:56 ` [Bug c++/9154] [3.4 regression] poor error message for ">>" vs. "> >" for nested template args giovannibajo at libero dot it
  2003-06-20 14:13 ` bangerth at dealii dot org
@ 2003-07-15 15:12 ` giovannibajo at libero dot it
  2003-10-27 13:19 ` giovannibajo at libero dot it
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: giovannibajo at libero dot it @ 2003-07-15 15:12 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9154



------- Additional Comments From giovannibajo at libero dot it  2003-07-15 15:12 -------
Patch (take 2) submitted
http://gcc.gnu.org/ml/gcc-patches/2003-06/msg02677.html


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

* [Bug c++/9154] [3.4 regression] poor error message for ">>" vs. "> >" for nested template args
       [not found] <20030103012600.9154.tilps@hotmail.com>
                   ` (2 preceding siblings ...)
  2003-07-15 15:12 ` giovannibajo at libero dot it
@ 2003-10-27 13:19 ` giovannibajo at libero dot it
  2003-12-01 13:00 ` giovannibajo at libero dot it
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: giovannibajo at libero dot it @ 2003-10-27 13:19 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9154



------- Additional Comments From giovannibajo at libero dot it  2003-10-27 12:54 -------
My patch does not apply anymore cleanly due to other modifies in mainline (made 
by Mark). I'll have to update it somehow.


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

* [Bug c++/9154] [3.4 regression] poor error message for ">>" vs. "> >" for nested template args
       [not found] <20030103012600.9154.tilps@hotmail.com>
                   ` (3 preceding siblings ...)
  2003-10-27 13:19 ` giovannibajo at libero dot it
@ 2003-12-01 13:00 ` giovannibajo at libero dot it
  2003-12-01 16:20 ` giovannibajo at libero dot it
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: giovannibajo at libero dot it @ 2003-12-01 13:00 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2003-12-01 13:00 -------
I'm updating my patch.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mmitchel at gcc dot gnu dot
                   |                            |org
         AssignedTo|gdr at gcc dot gnu dot org  |giovannibajo at libero dot
                   |                            |it


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9154


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

* [Bug c++/9154] [3.4 regression] poor error message for ">>" vs. "> >" for nested template args
       [not found] <20030103012600.9154.tilps@hotmail.com>
                   ` (4 preceding siblings ...)
  2003-12-01 13:00 ` giovannibajo at libero dot it
@ 2003-12-01 16:20 ` giovannibajo at libero dot it
  2003-12-05 16:43 ` giovannibajo at libero dot it
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: giovannibajo at libero dot it @ 2003-12-01 16:20 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2003-12-01 16:20 -------
Updated patch here. Better than before because it now detects also ">>" instead 
of single ">", and it does not emit any other spurious error. I also attacched 
a more complete testcase. I will test and submit it as soon as I have spare CPU 
time.


Index: parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.123
diff -c -p -r1.123 parser.c
*** parser.c	1 Dec 2003 05:58:22 -0000	1.123
--- parser.c	1 Dec 2003 16:14:55 -0000
*************** cp_parser_template_argument (cp_parser* 
*** 7936,7941 ****
--- 7936,7942 ----
    tree argument;
    bool template_p;
    bool address_p;
+   bool maybe_type_id = false;
    cp_token *token;
    cp_id_kind idk;
    tree qualifying_class;
*************** cp_parser_template_argument (cp_parser* 
*** 7952,7964 ****
       Therefore, we try a type-id first.  */
    cp_parser_parse_tentatively (parser);
    argument = cp_parser_type_id (parser);
!   /* If the next token isn't a `,' or a `>', then this argument wasn't
!      really finished.  */
!   if (!cp_parser_next_token_ends_template_argument_p (parser))
!     cp_parser_error (parser, "expected template-argument");
!   /* If that worked, we're done.  */
!   if (cp_parser_parse_definitely (parser))
!     return argument;
    /* We're still not sure what the argument will be.  */
    cp_parser_parse_tentatively (parser);
    /* Try a template.  */
--- 7953,7987 ----
       Therefore, we try a type-id first.  */
    cp_parser_parse_tentatively (parser);
    argument = cp_parser_type_id (parser);
!   /* If there was no error parsing the type-id but the next token is a '>>',
!      we probably found a typo for '> >'. But there are type-id which are 
!      also valid expressions. For instance:
! 
!      struct X { int operator >> (int); };
!      template <int V> struct Foo {};
!      Foo<X () >> 5> r;
! 
!      Here 'X()' is a valid type-id of a function type, but the user just
!      wanted to write the expression "X() >> 5". Thus, we remember that we
!      found a valid type-id, but we still try to parse the argument as an
!      expression to see what happens.  */
!   if (!cp_parser_error_occurred (parser)
!       && cp_lexer_next_token_is (parser->lexer, CPP_RSHIFT))
!   {
!     maybe_type_id = true;
!     cp_parser_abort_tentative_parse (parser);
!   }
!   else
!   {
!     /* If the next token isn't a `,' or a `>', then this argument wasn't
!     really finished. This means that the argument is not a valid
!     type-id.  */
!     if (!cp_parser_next_token_ends_template_argument_p (parser))
!       cp_parser_error (parser, "expected template-argument");
!     /* If that worked, we're done.  */
!     if (cp_parser_parse_definitely (parser))
!       return argument;
!   }
    /* We're still not sure what the argument will be.  */
    cp_parser_parse_tentatively (parser);
    /* Try a template.  */
*************** cp_parser_template_argument (cp_parser* 
*** 8073,8084 ****
        cp_parser_error (parser, "invalid non-type template argument");
        return error_mark_node;
      }
!   /* The argument must be a constant-expression.  */
    argument = cp_parser_constant_expression (parser, 
  					    /*allow_non_constant_p=*/false,
  					    /*non_constant_p=*/NULL);
!   /* If it's non-dependent, simplify it.  */
!   return cp_parser_fold_non_dependent_expr (argument);
  }
  
  /* Parse an explicit-instantiation.
--- 8096,8122 ----
        cp_parser_error (parser, "invalid non-type template argument");
        return error_mark_node;
      }
!   /* If the argument wasn't successfully parsed as a type-id followed
!      by '>>', the argument can only be a constant expression now.  
!      Otherwise, we try parsing the constant-expression tentatively,
!      because the argument could really be a type-id.  */
!   if (maybe_type_id)
!     cp_parser_parse_tentatively (parser);
    argument = cp_parser_constant_expression (parser, 
  					    /*allow_non_constant_p=*/false,
  					    /*non_constant_p=*/NULL);
!   argument = cp_parser_fold_non_dependent_expr (argument);
!   if (!maybe_type_id)
!     return argument;
!   if (!cp_parser_next_token_ends_template_argument_p (parser))
!     cp_parser_error (parser, "expected template-argument");
!   if (cp_parser_parse_definitely (parser))
!     return argument;
!   /* We did our best to parse the argument as a non type-id, but that
!      was the only alternative that matched (albeit with a '>' after
!      it). We can assume it's just a typo from the user, and a 
!      diagnostic will then be issued.  */
!   return cp_parser_type_id (parser);
  }
  
  /* Parse an explicit-instantiation.
*************** cp_parser_enclosed_template_argument_lis
*** 14009,14016 ****
      arguments = NULL_TREE;
    else
      arguments = cp_parser_template_argument_list (parser);
!   /* Look for the `>' that ends the template-argument-list.  */
!   cp_parser_require (parser, CPP_GREATER, "`>'");
    /* The `>' token might be a greater-than operator again now.  */
    parser->greater_than_is_operator_p 
      = saved_greater_than_is_operator_p;
--- 14047,14077 ----
      arguments = NULL_TREE;
    else
      arguments = cp_parser_template_argument_list (parser);
!   /* Look for the `>' that ends the template-argument-list. If we find
!      a '>>' instead, it's probably just a typo.  */
!   if (cp_lexer_next_token_is (parser->lexer, CPP_RSHIFT))
!   {
!     if (!saved_greater_than_is_operator_p)
!     {
!       /* If we're in a nested template argument list, the '>>' has to be
! 	 a typo for '> >'. We emit the error message, but we continue
! 	 parsing and we push a '>' as next token, so that the argument
! 	 list will be parsed correctly..  */
!       cp_token* token;
!       error ("`>>' should be `> >' within a nested template argument list");
!       token = cp_lexer_peek_token (parser->lexer);
!       token->type = CPP_GREATER;
!     }
!     else
!     {
!       /* If this is not a nested template argument list, the '>>' is
!          a typo for '> >'. Emit an error message and continue.  */
!       error ("spurious `>>', use `>' to terminate a template argument list");
!       cp_lexer_consume_token (parser->lexer);
!     }
!   }
!   else
!     cp_parser_require (parser, CPP_GREATER, "`>'");
    /* The `>' token might be a greater-than operator again now.  */
    parser->greater_than_is_operator_p 
      = saved_greater_than_is_operator_p;
*************** cp_parser_next_token_starts_class_defini
*** 14451,14457 ****
  }
  
  /* Returns TRUE iff the next token is the "," or ">" ending a
!    template-argument.  */
  
  static bool
  cp_parser_next_token_ends_template_argument_p (cp_parser *parser)
--- 14512,14520 ----
  }
  
  /* Returns TRUE iff the next token is the "," or ">" ending a
!    template-argument. ">>" is also accepted (after the full
!    argument was parsed) because it's probably a typo for "> >",
!    and there is a specific diagnostic for this.  */
  
  static bool
  cp_parser_next_token_ends_template_argument_p (cp_parser *parser)
*************** cp_parser_next_token_ends_template_argum
*** 14459,14465 ****
    cp_token *token;
  
    token = cp_lexer_peek_token (parser->lexer);
!   return (token->type == CPP_COMMA || token->type == CPP_GREATER);
  }
   
  /* Returns the kind of tag indicated by TOKEN, if it is a class-key,
--- 14522,14529 ----
    cp_token *token;
  
    token = cp_lexer_peek_token (parser->lexer);
!   return (token->type == CPP_COMMA || token->type == CPP_GREATER 
! 	  || token->type == CPP_LSHIFT);
  }
   
  /* Returns the kind of tag indicated by TOKEN, if it is a class-key,


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9154


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

* [Bug c++/9154] [3.4 regression] poor error message for ">>" vs. "> >" for nested template args
       [not found] <20030103012600.9154.tilps@hotmail.com>
                   ` (5 preceding siblings ...)
  2003-12-01 16:20 ` giovannibajo at libero dot it
@ 2003-12-05 16:43 ` giovannibajo at libero dot it
  2003-12-18 12:13 ` cvs-commit at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: giovannibajo at libero dot it @ 2003-12-05 16:43 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2003-12-05 16:43 -------
Waiting for review:
http://gcc.gnu.org/ml/gcc-patches/2003-12/msg00534.html

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9154


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

* [Bug c++/9154] [3.4 regression] poor error message for ">>" vs. "> >" for nested template args
       [not found] <20030103012600.9154.tilps@hotmail.com>
                   ` (6 preceding siblings ...)
  2003-12-05 16:43 ` giovannibajo at libero dot it
@ 2003-12-18 12:13 ` cvs-commit at gcc dot gnu dot org
  2003-12-18 12:21 ` cvs-commit at gcc dot gnu dot org
  2003-12-18 12:38 ` giovannibajo at libero dot it
  9 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2003-12-18 12:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2003-12-18 11:51 -------
Subject: Bug 9154

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	giovannibajo@gcc.gnu.org	2003-12-18 11:50:58

Modified files:
	gcc/cp         : ChangeLog parser.c 

Log message:
	PR c++/9154
	* parser.c (cp_parser_template_argument): A type-id followed by '>>'
	is just an user typo, and should be accepted as last resort if any
	other parsing fails.
	(cp_parser_enclosed_template_argument_list): If the argument list is
	parsed correctly, but the next token is '>>', emit a diagnostic.
	(cp_parser_next_token_ends_template_argument): Accept '>>' as
	delimiter of template argument, it will be later detected as a typo.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3817&r2=1.3818
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.136&r2=1.137



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9154


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

* [Bug c++/9154] [3.4 regression] poor error message for ">>" vs. "> >" for nested template args
       [not found] <20030103012600.9154.tilps@hotmail.com>
                   ` (7 preceding siblings ...)
  2003-12-18 12:13 ` cvs-commit at gcc dot gnu dot org
@ 2003-12-18 12:21 ` cvs-commit at gcc dot gnu dot org
  2003-12-18 12:38 ` giovannibajo at libero dot it
  9 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2003-12-18 12:21 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2003-12-18 12:00 -------
Subject: Bug 9154

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	giovannibajo@gcc.gnu.org	2003-12-18 12:00:08

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/template: error10.C 

Log message:
	PR c++/9154
	* g++.dg/template/error10.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3278&r2=1.3279
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/error10.C.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9154


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

* [Bug c++/9154] [3.4 regression] poor error message for ">>" vs. "> >" for nested template args
       [not found] <20030103012600.9154.tilps@hotmail.com>
                   ` (8 preceding siblings ...)
  2003-12-18 12:21 ` cvs-commit at gcc dot gnu dot org
@ 2003-12-18 12:38 ` giovannibajo at libero dot it
  9 siblings, 0 replies; 10+ messages in thread
From: giovannibajo at libero dot it @ 2003-12-18 12:38 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2003-12-18 12:08 -------
Final patch: http://gcc.gnu.org/ml/gcc-patches/2003-12/msg01495.html
Approval: http://gcc.gnu.org/ml/gcc-patches/2003-12/msg01548.html

This bug is now fixed in GCC 3.4.0. Thanks!

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9154


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

end of thread, other threads:[~2003-12-18 12:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20030103012600.9154.tilps@hotmail.com>
2003-06-20 13:56 ` [Bug c++/9154] [3.4 regression] poor error message for ">>" vs. "> >" for nested template args giovannibajo at libero dot it
2003-06-20 14:13 ` bangerth at dealii dot org
2003-07-15 15:12 ` giovannibajo at libero dot it
2003-10-27 13:19 ` giovannibajo at libero dot it
2003-12-01 13:00 ` giovannibajo at libero dot it
2003-12-01 16:20 ` giovannibajo at libero dot it
2003-12-05 16:43 ` giovannibajo at libero dot it
2003-12-18 12:13 ` cvs-commit at gcc dot gnu dot org
2003-12-18 12:21 ` cvs-commit at gcc dot gnu dot org
2003-12-18 12:38 ` giovannibajo at libero dot it

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