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] |
This patch implements the "right angle brackets" feature of C++0x, which is part of the current C++0x working draft (and has been for a while). Essentially, it allows users to write, e.g.,
and it will parse the ">>" token as two separate ">" tokens, ending the two, nested template argument lists. Essentially, C++0x uses the same rule for ">>" tokens when there is an active "<" (for a template argument list or a new-style case) as it does for ">" tokens, breaking apart ">>" into ">" and ">".
This new behavior is only available when we're in C++0x mode, which is particularly important because it breaks some existing programs. For example, the following is legal C++98 but ill-formed C++0x:
template<int> struct X { }; X<100 >> 2> x; // ">>" is a right-shift operator in C++98, two ">" tokens in C++0x
This patch, of course, maintains the C++98 behavior in the default C++98 mode and uses the C++0x behavior in C++0x mode. When the C++0x compatibility warnings (-Wc++0x-compat) are turned on, this patch will warn about cases where the behavior will change and suggest that the user put parentheses around the expression.
Cheers, Doug
* parser.c (struct cp_parser): Update comment for greater_than_is_operator_p. (cp_parser_primary_expression): In C++0x mode, a cast operator can be terminated with a `>>' token when !GREATER_THAN_IS_OPERATOR_P. (TOKEN_PRECEDENCE): In C++0x mode, `>>' is treated like `>' when !GREATER_THAN_IS_OPERATOR_P. (cp_parser_binary_expression): When -Wc++0x-compat, warn about `>>' operators that will become two `>' tokens in C++0x. (cp_parser_parameter_declaration): Treate `>>' like `>' in C++0x mode, allowing it to terminate default arguments. (cp_parser_enclosed_template_argument_list): In C++0x mode, treat `>>' like two consecutive `>' tokens. (cp_parser_skip_to_end_of_template_parameter_list): Ditto. (cp_parser_next_token_ends_template_argument_p): In C++0x, `>>' ends a template argument.
* g++.dg/cpp0x/bracket1.C: New. * g++.dg/cpp0x/bracket2.C: New. * g++.dg/cpp0x/bracket3.C: New.
Attachment:
rangle-cp.patch
Description: Binary data
Attachment:
rangle-testsuite.patch
Description: Binary data
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |