This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ patch]: Fix bug 10
- To: gcc-patches at gcc dot gnu dot org
- Subject: [C++ patch]: Fix bug 10
- From: Nathan Sidwell <nathan at codesourcery dot com>
- Date: Fri, 30 Jun 2000 10:53:19 +0100
- Organization: Codesourcery LLC
Hi,
I've installed the attached patch and testcase to fix bug 10.
Bison's precidence rules don't work on something like
TPL<a && b> thing;
The solution is to split the grammer for expressions inside
template < ... >.
Approved by Mark, booted and tested on i686-pc-linux-gnu
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2000-06-30 Nathan Sidwell <nathan@codesourcery.com>
* parse.y (expr_no_comma_rangle): New non-terminal.
(template_parm): Use it for default parameter case.
(template_arg): Use it.
(expr_no_commas): Remove commented out undefined extensions.
* Makefile.in (CONFLICTS): Adjust to 33 s/r & 48 r/r.
* parse.h, parse.c: Rebuilt.
Index: cp/parse.y
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/parse.y,v
retrieving revision 1.180
diff -c -3 -p -r1.180 parse.y
*** parse.y 2000/06/24 22:17:18 1.180
--- parse.y 2000/06/30 08:26:19
*************** cp_parse_init ()
*** 325,331 ****
%type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist
%type <ttype> PFUNCNAME maybe_identifier
%type <ttype> paren_expr_or_null nontrivial_exprlist SELFNAME
! %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
%type <ttype> reserved_declspecs boolean.literal
%type <ttype> reserved_typespecquals
%type <ttype> SCSPEC TYPESPEC CV_QUALIFIER maybe_cv_qualifier
--- 325,332 ----
%type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist
%type <ttype> PFUNCNAME maybe_identifier
%type <ttype> paren_expr_or_null nontrivial_exprlist SELFNAME
! %type <ttype> expr_no_commas expr_no_comma_rangle
! %type <ttype> cast_expr unary_expr primary string STRING
%type <ttype> reserved_declspecs boolean.literal
%type <ttype> reserved_typespecquals
%type <ttype> SCSPEC TYPESPEC CV_QUALIFIER maybe_cv_qualifier
*************** template_parm:
*** 641,647 ****
{ $$ = build_tree_list (groktypename ($3.t), $1); }
| parm
{ $$ = build_tree_list (NULL_TREE, $1.t); }
! | parm '=' expr_no_commas %prec ARITHCOMPARE
{ $$ = build_tree_list ($3, $1.t); }
| template_template_parm
{ $$ = build_tree_list (NULL_TREE, $1); }
--- 642,648 ----
{ $$ = build_tree_list (groktypename ($3.t), $1); }
| parm
{ $$ = build_tree_list (NULL_TREE, $1.t); }
! | parm '=' expr_no_comma_rangle
{ $$ = build_tree_list ($3, $1.t); }
| template_template_parm
{ $$ = build_tree_list (NULL_TREE, $1); }
*************** template_arg:
*** 1065,1071 ****
if (DECL_TEMPLATE_TEMPLATE_PARM_P ($$))
$$ = TREE_TYPE ($$);
}
! | expr_no_commas %prec ARITHCOMPARE
;
unop:
--- 1066,1072 ----
if (DECL_TEMPLATE_TEMPLATE_PARM_P ($$))
$$ = TREE_TYPE ($$);
}
! | expr_no_comma_rangle
;
unop:
*************** expr_no_commas:
*** 1368,1386 ****
{ $$ = build_throw (NULL_TREE); }
| THROW expr_no_commas
{ $$ = build_throw ($2); }
! /* These extensions are not defined. The second arg to build_m_component_ref
! is old, build_m_component_ref now does an implicit
! build_indirect_ref (x, NULL_PTR) on the second argument.
! | object '&' expr_no_commas %prec UNARY
! { $$ = build_m_component_ref ($$, build_x_unary_op (ADDR_EXPR, $3)); }
! | object unop expr_no_commas %prec UNARY
! { $$ = build_m_component_ref ($$, build_x_unary_op ($2, $3)); }
! | object '(' type_id ')' expr_no_commas %prec UNARY
! { tree type = groktypename ($3.t);
! $$ = build_m_component_ref ($$, build_c_cast (type, $5)); }
! | object primary_no_id %prec UNARY
! { $$ = build_m_component_ref ($$, $2); }
! */
;
notype_unqualified_id:
--- 1369,1427 ----
{ $$ = build_throw (NULL_TREE); }
| THROW expr_no_commas
{ $$ = build_throw ($2); }
! ;
!
! expr_no_comma_rangle:
! cast_expr
! /* Handle general members. */
! | expr_no_comma_rangle POINTSAT_STAR expr_no_comma_rangle
! { $$ = build_x_binary_op (MEMBER_REF, $$, $3); }
! | expr_no_comma_rangle DOT_STAR expr_no_comma_rangle
! { $$ = build_m_component_ref ($$, $3); }
! | expr_no_comma_rangle '+' expr_no_comma_rangle
! { $$ = build_x_binary_op ($2, $$, $3); }
! | expr_no_comma_rangle '-' expr_no_comma_rangle
! { $$ = build_x_binary_op ($2, $$, $3); }
! | expr_no_comma_rangle '*' expr_no_comma_rangle
! { $$ = build_x_binary_op ($2, $$, $3); }
! | expr_no_comma_rangle '/' expr_no_comma_rangle
! { $$ = build_x_binary_op ($2, $$, $3); }
! | expr_no_comma_rangle '%' expr_no_comma_rangle
! { $$ = build_x_binary_op ($2, $$, $3); }
! | expr_no_comma_rangle LSHIFT expr_no_comma_rangle
! { $$ = build_x_binary_op ($2, $$, $3); }
! | expr_no_comma_rangle RSHIFT expr_no_comma_rangle
! { $$ = build_x_binary_op ($2, $$, $3); }
! | expr_no_comma_rangle ARITHCOMPARE expr_no_comma_rangle
! { $$ = build_x_binary_op ($2, $$, $3); }
! | expr_no_comma_rangle '<' expr_no_comma_rangle
! { $$ = build_x_binary_op (LT_EXPR, $$, $3); }
! | expr_no_comma_rangle EQCOMPARE expr_no_comma_rangle
! { $$ = build_x_binary_op ($2, $$, $3); }
! | expr_no_comma_rangle MIN_MAX expr_no_comma_rangle
! { $$ = build_x_binary_op ($2, $$, $3); }
! | expr_no_comma_rangle '&' expr_no_comma_rangle
! { $$ = build_x_binary_op ($2, $$, $3); }
! | expr_no_comma_rangle '|' expr_no_comma_rangle
! { $$ = build_x_binary_op ($2, $$, $3); }
! | expr_no_comma_rangle '^' expr_no_comma_rangle
! { $$ = build_x_binary_op ($2, $$, $3); }
! | expr_no_comma_rangle ANDAND expr_no_comma_rangle
! { $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $$, $3); }
! | expr_no_comma_rangle OROR expr_no_comma_rangle
! { $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $$, $3); }
! | expr_no_comma_rangle '?' xexpr ':' expr_no_comma_rangle
! { $$ = build_x_conditional_expr ($$, $3, $5); }
! | expr_no_comma_rangle '=' expr_no_comma_rangle
! { $$ = build_x_modify_expr ($$, NOP_EXPR, $3);
! if ($$ != error_mark_node)
! C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
! | expr_no_comma_rangle ASSIGN expr_no_comma_rangle
! { $$ = build_x_modify_expr ($$, $2, $3); }
! | THROW
! { $$ = build_throw (NULL_TREE); }
! | THROW expr_no_comma_rangle
! { $$ = build_throw ($2); }
;
notype_unqualified_id:
Index: cp/Makefile.in
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/Makefile.in,v
retrieving revision 1.91
diff -c -3 -p -r1.91 Makefile.in
*** Makefile.in 2000/06/24 22:17:13 1.91
--- Makefile.in 2000/06/30 08:26:19
*************** parse.o : $(PARSE_C) $(CXX_TREE_H) $(src
*** 219,225 ****
$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(BIG_SWITCHFLAG) \
`echo $(PARSE_C) | sed 's,^\./,,'`
! CONFLICTS = expect 32 shift/reduce conflicts and 58 reduce/reduce conflicts.
$(PARSE_H) : $(PARSE_C)
$(PARSE_C) : $(srcdir)/parse.y
@echo $(CONFLICTS)
--- 219,225 ----
$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(BIG_SWITCHFLAG) \
`echo $(PARSE_C) | sed 's,^\./,,'`
! CONFLICTS = expect 33 shift/reduce conflicts and 58 reduce/reduce conflicts.
$(PARSE_H) : $(PARSE_C)
$(PARSE_C) : $(srcdir)/parse.y
@echo $(CONFLICTS)
2000-06-30 Nathan Sidwell <nathan@codesourcery.com>
* g++.old-deja/g++.pt/expr8.C: New test.
* g++.old-deja/g++.pt/expr6.C: Remove XFAIL.
Index: g++.old-deja/g++.pt/expr6.C
===================================================================
RCS file: /cvs/gcc/egcs/gcc/testsuite/g++.old-deja/g++.pt/expr6.C,v
retrieving revision 1.2
diff -c -3 -p -r1.2 expr6.C
*** expr6.C 1998/12/16 21:56:16 1.2
--- expr6.C 2000/06/30 08:29:10
***************
*** 2,9 ****
// Based on a bug report by tveldhui <tveldhui@extreme.indiana.edu>
- // excess errors test - XFAIL *-*-*
-
template <int X> class foo {};
foo< true ? 1 : 0 > bar;
--- 2,7 ----
Index: g++.old-deja/g++.pt/expr8.C
===================================================================
RCS file: expr8.C
diff -N expr8.C
*** /dev/null Tue May 5 13:32:27 1998
--- expr8.C Fri Jun 30 01:29:10 2000
***************
*** 0 ****
--- 1,26 ----
+ // Build don't link:
+
+ // Copyright (C) 2000 Free Software Foundation, Inc.
+ // Contributed by Nathan Sidwell 23 June 2000 <nathan@codesourcery.com>
+
+ // Origin GNATS bug report 10 from Ewgenij Gawrilow <gawrilow@math.TU-Berlin.DE>
+ // There is a grammar ambiguity with greater-than compare as a default
+ // template parameter value or template arg list. 14.2/2 and 14.1/15
+ // say how to resolve it, but we'd sometimes get it wrong.
+
+ template <int> class C { };
+
+ void f()
+ {
+ C<1> c1;
+ C<1 & 2> c2;
+ C<1>2> c3; // ERROR - parse error
+ C<(1>2)> c4;
+ C<1 & 2>2> c5; // ERROR - parse error
+ C<1 & (2>2)> c6;
+ }
+
+ template <int i = 3>4 > class X1 {}; // ERROR - parse error
+ template <int i = 3&&4>0 > class X2 {}; // ERROR - parse error
+ template <int i = 3&&4 > class X3 {};
+ template <int i = (3>4) > class X4 {};