From 4e74ff8c65832a02f87b2b16e23219bfd4925137 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 4 Mar 2016 14:40:30 -0500 Subject: [PATCH 02/14] FIXME: C++ FE: WIP on underlines for operators --- gcc/cp/parser.c | 12 +++++++++++- .../g++.dg/diagnostic/operator-underlining.C | 21 +++++++++++++++++++++ gcc/testsuite/lib/multiline.exp | 4 ++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/diagnostic/operator-underlining.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 7197c19..0622fb0 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -20050,7 +20050,17 @@ cp_parser_direct_declarator (cp_parser* parser, unqualified_name, sfk); declarator->std_attributes = attrs; - declarator->id_loc = token->location; + /* Construct a location of the form: + extern bool operator && (foo& lhs, foo& rhs); + ^~~~~~~~~~~ + with caret == start at the token location, ranging to the + end of the final token. */ + location_t start_loc = token->location; + location_t finish_loc + = get_finish (cp_lexer_previous_token (parser->lexer)->location); + location_t combined_loc = make_location (start_loc, start_loc, + finish_loc); + declarator->id_loc = combined_loc; declarator->parameter_pack_p = pack_expansion_p; if (pack_expansion_p) diff --git a/gcc/testsuite/g++.dg/diagnostic/operator-underlining.C b/gcc/testsuite/g++.dg/diagnostic/operator-underlining.C new file mode 100644 index 0000000..927d6bf --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/operator-underlining.C @@ -0,0 +1,21 @@ +/* Verify that we fully underline overloaded operators, rather + than just the "operator" token. */ +// { dg-options "-fdiagnostics-show-caret" } + +struct foo; +struct bar; + +extern bool operator && (foo& lhs, foo& rhs); +/* { dg-begin-multiline-output "" } + extern bool operator && (foo& lhs, foo& rhs); + ^~~~~~~~~~~ + { dg-end-multiline-output "" } */ + +bool test (bar &lhs, bar &rhs) +{ + return lhs && rhs; // { dg-error "no match for" } +/* { dg-begin-multiline-output "" } + return lhs && rhs; + ~~~~^~~~~~ + { dg-end-multiline-output "" } */ +} diff --git a/gcc/testsuite/lib/multiline.exp b/gcc/testsuite/lib/multiline.exp index cde9240..94956009 100644 --- a/gcc/testsuite/lib/multiline.exp +++ b/gcc/testsuite/lib/multiline.exp @@ -234,6 +234,10 @@ proc _build_multiline_regex { multiline index } { append rexp "\n" } + # Remove the "\n" from the final line: + set rexp [string trimright $rexp] + # FIXME: ^^^ + # dg.exp's dg-test trims leading whitespace from the output # in this line: # set comp_output [string trimleft $comp_output] -- 1.8.5.3