re PR c++/87386 (Error message for static_assert show wrong range)
PR c++/87386 * parser.c (cp_parser_primary_expression): Use id_expression.get_location () instead of id_expr_token->location. Adjust the range from id_expr_token->location to id_expressio.get_finish (). (cp_parser_operator_function_id): Pass location of the operator token down to cp_parser_operator. (cp_parser_operator): Add start_loc argument, always construct a location with caret at start_loc and range from start_loc to the finish of the last token. gcc/testsuite/ * g++.dg/diagnostic/pr87386.C: New test. * g++.dg/parse/error17.C: Adjust expected diagnostics. libstdc++-v3/ * testsuite/20_util/scoped_allocator/69293_neg.cc: Adjust expected line. * testsuite/20_util/uses_allocator/cons_neg.cc: Likewise. * testsuite/20_util/uses_allocator/69293_neg.cc: Likewise. * testsuite/experimental/propagate_const/requirements2.cc: Likewise. * testsuite/experimental/propagate_const/requirements3.cc: Likewise. * testsuite/experimental/propagate_const/requirements4.cc: Likewise. * testsuite/experimental/propagate_const/requirements5.cc: Likewise. From-SVN: r266359
This commit is contained in:
parent
13986a58e7
commit
e1389417f9
|
@ -1,5 +1,16 @@
|
||||||
2018-11-21 Jakub Jelinek <jakub@redhat.com>
|
2018-11-21 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
|
PR c++/87386
|
||||||
|
* parser.c (cp_parser_primary_expression): Use
|
||||||
|
id_expression.get_location () instead of id_expr_token->location.
|
||||||
|
Adjust the range from id_expr_token->location to
|
||||||
|
id_expressio.get_finish ().
|
||||||
|
(cp_parser_operator_function_id): Pass location of the operator
|
||||||
|
token down to cp_parser_operator.
|
||||||
|
(cp_parser_operator): Add start_loc argument, always construct a
|
||||||
|
location with caret at start_loc and range from start_loc to the
|
||||||
|
finish of the last token.
|
||||||
|
|
||||||
PR c++/87393
|
PR c++/87393
|
||||||
* parser.c (cp_parser_linkage_specification): Remove useless
|
* parser.c (cp_parser_linkage_specification): Remove useless
|
||||||
dereference of the consume_open method result.
|
dereference of the consume_open method result.
|
||||||
|
|
|
@ -2312,7 +2312,7 @@ static tree cp_parser_mem_initializer_id
|
||||||
static cp_expr cp_parser_operator_function_id
|
static cp_expr cp_parser_operator_function_id
|
||||||
(cp_parser *);
|
(cp_parser *);
|
||||||
static cp_expr cp_parser_operator
|
static cp_expr cp_parser_operator
|
||||||
(cp_parser *);
|
(cp_parser *, location_t);
|
||||||
|
|
||||||
/* Templates [gram.temp] */
|
/* Templates [gram.temp] */
|
||||||
|
|
||||||
|
@ -5604,7 +5604,7 @@ cp_parser_primary_expression (cp_parser *parser,
|
||||||
/*is_namespace=*/false,
|
/*is_namespace=*/false,
|
||||||
/*check_dependency=*/true,
|
/*check_dependency=*/true,
|
||||||
&ambiguous_decls,
|
&ambiguous_decls,
|
||||||
id_expr_token->location);
|
id_expression.get_location ());
|
||||||
/* If the lookup was ambiguous, an error will already have
|
/* If the lookup was ambiguous, an error will already have
|
||||||
been issued. */
|
been issued. */
|
||||||
if (ambiguous_decls)
|
if (ambiguous_decls)
|
||||||
|
@ -5675,7 +5675,7 @@ cp_parser_primary_expression (cp_parser *parser,
|
||||||
if (parser->local_variables_forbidden_p
|
if (parser->local_variables_forbidden_p
|
||||||
&& local_variable_p (decl))
|
&& local_variable_p (decl))
|
||||||
{
|
{
|
||||||
error_at (id_expr_token->location,
|
error_at (id_expression.get_location (),
|
||||||
"local variable %qD may not appear in this context",
|
"local variable %qD may not appear in this context",
|
||||||
decl.get_value ());
|
decl.get_value ());
|
||||||
return error_mark_node;
|
return error_mark_node;
|
||||||
|
@ -5694,7 +5694,8 @@ cp_parser_primary_expression (cp_parser *parser,
|
||||||
id_expression.get_location ()));
|
id_expression.get_location ()));
|
||||||
if (error_msg)
|
if (error_msg)
|
||||||
cp_parser_error (parser, error_msg);
|
cp_parser_error (parser, error_msg);
|
||||||
decl.set_location (id_expr_token->location);
|
decl.set_location (id_expression.get_location ());
|
||||||
|
decl.set_range (id_expr_token->location, id_expression.get_finish ());
|
||||||
return decl;
|
return decl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15011,11 +15012,12 @@ cp_parser_mem_initializer_id (cp_parser* parser)
|
||||||
static cp_expr
|
static cp_expr
|
||||||
cp_parser_operator_function_id (cp_parser* parser)
|
cp_parser_operator_function_id (cp_parser* parser)
|
||||||
{
|
{
|
||||||
|
location_t start_loc = cp_lexer_peek_token (parser->lexer)->location;
|
||||||
/* Look for the `operator' keyword. */
|
/* Look for the `operator' keyword. */
|
||||||
if (!cp_parser_require_keyword (parser, RID_OPERATOR, RT_OPERATOR))
|
if (!cp_parser_require_keyword (parser, RID_OPERATOR, RT_OPERATOR))
|
||||||
return error_mark_node;
|
return error_mark_node;
|
||||||
/* And then the name of the operator itself. */
|
/* And then the name of the operator itself. */
|
||||||
return cp_parser_operator (parser);
|
return cp_parser_operator (parser, start_loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return an identifier node for a user-defined literal operator.
|
/* Return an identifier node for a user-defined literal operator.
|
||||||
|
@ -15049,7 +15051,7 @@ cp_literal_operator_id (const char* name)
|
||||||
human-readable spelling of the identifier, e.g., `operator +'. */
|
human-readable spelling of the identifier, e.g., `operator +'. */
|
||||||
|
|
||||||
static cp_expr
|
static cp_expr
|
||||||
cp_parser_operator (cp_parser* parser)
|
cp_parser_operator (cp_parser* parser, location_t start_loc)
|
||||||
{
|
{
|
||||||
tree id = NULL_TREE;
|
tree id = NULL_TREE;
|
||||||
cp_token *token;
|
cp_token *token;
|
||||||
|
@ -15058,7 +15060,7 @@ cp_parser_operator (cp_parser* parser)
|
||||||
/* Peek at the next token. */
|
/* Peek at the next token. */
|
||||||
token = cp_lexer_peek_token (parser->lexer);
|
token = cp_lexer_peek_token (parser->lexer);
|
||||||
|
|
||||||
location_t start_loc = token->location;
|
location_t end_loc = token->location;
|
||||||
|
|
||||||
/* Figure out which operator we have. */
|
/* Figure out which operator we have. */
|
||||||
enum tree_code op = ERROR_MARK;
|
enum tree_code op = ERROR_MARK;
|
||||||
|
@ -15077,7 +15079,7 @@ cp_parser_operator (cp_parser* parser)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Consume the `new' or `delete' token. */
|
/* Consume the `new' or `delete' token. */
|
||||||
location_t end_loc = cp_lexer_consume_token (parser->lexer)->location;
|
end_loc = cp_lexer_consume_token (parser->lexer)->location;
|
||||||
|
|
||||||
/* Peek at the next token. */
|
/* Peek at the next token. */
|
||||||
token = cp_lexer_peek_token (parser->lexer);
|
token = cp_lexer_peek_token (parser->lexer);
|
||||||
|
@ -15093,7 +15095,6 @@ cp_parser_operator (cp_parser* parser)
|
||||||
end_loc = close_token->location;
|
end_loc = close_token->location;
|
||||||
op = op == NEW_EXPR ? VEC_NEW_EXPR : VEC_DELETE_EXPR;
|
op = op == NEW_EXPR ? VEC_NEW_EXPR : VEC_DELETE_EXPR;
|
||||||
}
|
}
|
||||||
start_loc = make_location (start_loc, start_loc, end_loc);
|
|
||||||
consumed = true;
|
consumed = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -15259,7 +15260,9 @@ cp_parser_operator (cp_parser* parser)
|
||||||
matching_parens parens;
|
matching_parens parens;
|
||||||
parens.consume_open (parser);
|
parens.consume_open (parser);
|
||||||
/* Look for the matching `)'. */
|
/* Look for the matching `)'. */
|
||||||
parens.require_close (parser);
|
token = parens.require_close (parser);
|
||||||
|
if (token)
|
||||||
|
end_loc = token->location;
|
||||||
op = CALL_EXPR;
|
op = CALL_EXPR;
|
||||||
consumed = true;
|
consumed = true;
|
||||||
break;
|
break;
|
||||||
|
@ -15269,7 +15272,9 @@ cp_parser_operator (cp_parser* parser)
|
||||||
/* Consume the `['. */
|
/* Consume the `['. */
|
||||||
cp_lexer_consume_token (parser->lexer);
|
cp_lexer_consume_token (parser->lexer);
|
||||||
/* Look for the matching `]'. */
|
/* Look for the matching `]'. */
|
||||||
cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
|
token = cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
|
||||||
|
if (token)
|
||||||
|
end_loc = token->location;
|
||||||
op = ARRAY_REF;
|
op = ARRAY_REF;
|
||||||
consumed = true;
|
consumed = true;
|
||||||
break;
|
break;
|
||||||
|
@ -15287,7 +15292,8 @@ cp_parser_operator (cp_parser* parser)
|
||||||
case CPP_STRING16_USERDEF:
|
case CPP_STRING16_USERDEF:
|
||||||
case CPP_STRING32_USERDEF:
|
case CPP_STRING32_USERDEF:
|
||||||
{
|
{
|
||||||
tree str, string_tree;
|
cp_expr str;
|
||||||
|
tree string_tree;
|
||||||
int sz, len;
|
int sz, len;
|
||||||
|
|
||||||
if (cxx_dialect == cxx98)
|
if (cxx_dialect == cxx98)
|
||||||
|
@ -15302,6 +15308,7 @@ cp_parser_operator (cp_parser* parser)
|
||||||
{
|
{
|
||||||
string_tree = USERDEF_LITERAL_VALUE (str);
|
string_tree = USERDEF_LITERAL_VALUE (str);
|
||||||
id = USERDEF_LITERAL_SUFFIX_ID (str);
|
id = USERDEF_LITERAL_SUFFIX_ID (str);
|
||||||
|
end_loc = str.get_location ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -15309,7 +15316,10 @@ cp_parser_operator (cp_parser* parser)
|
||||||
/* Look for the suffix identifier. */
|
/* Look for the suffix identifier. */
|
||||||
token = cp_lexer_peek_token (parser->lexer);
|
token = cp_lexer_peek_token (parser->lexer);
|
||||||
if (token->type == CPP_NAME)
|
if (token->type == CPP_NAME)
|
||||||
id = cp_parser_identifier (parser);
|
{
|
||||||
|
id = cp_parser_identifier (parser);
|
||||||
|
end_loc = token->location;
|
||||||
|
}
|
||||||
else if (token->type == CPP_KEYWORD)
|
else if (token->type == CPP_KEYWORD)
|
||||||
{
|
{
|
||||||
error ("unexpected keyword;"
|
error ("unexpected keyword;"
|
||||||
|
@ -15341,7 +15351,8 @@ cp_parser_operator (cp_parser* parser)
|
||||||
const char *name = IDENTIFIER_POINTER (id);
|
const char *name = IDENTIFIER_POINTER (id);
|
||||||
id = cp_literal_operator_id (name);
|
id = cp_literal_operator_id (name);
|
||||||
}
|
}
|
||||||
return id;
|
start_loc = make_location (start_loc, start_loc, get_finish (end_loc));
|
||||||
|
return cp_expr (id, start_loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -15364,6 +15375,7 @@ cp_parser_operator (cp_parser* parser)
|
||||||
id = error_mark_node;
|
id = error_mark_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
start_loc = make_location (start_loc, start_loc, get_finish (end_loc));
|
||||||
return cp_expr (id, start_loc);
|
return cp_expr (id, start_loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
2018-11-21 Jakub Jelinek <jakub@redhat.com>
|
2018-11-21 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
|
PR c++/87386
|
||||||
|
* g++.dg/diagnostic/pr87386.C: New test.
|
||||||
|
* g++.dg/parse/error17.C: Adjust expected diagnostics.
|
||||||
|
|
||||||
PR rtl-optimization/85925
|
PR rtl-optimization/85925
|
||||||
* gcc.c-torture/execute/20181120-1.c: Require effective target
|
* gcc.c-torture/execute/20181120-1.c: Require effective target
|
||||||
int32plus.
|
int32plus.
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
// PR c++/87386
|
||||||
|
// { dg-do compile { target c++11 } }
|
||||||
|
// { dg-options "-fdiagnostics-show-caret" }
|
||||||
|
|
||||||
|
namespace foo {
|
||||||
|
template<typename> struct test { static constexpr bool value = false; };
|
||||||
|
}
|
||||||
|
static_assert (foo::test<int>::value, "foo"); // { dg-error "static assertion failed: foo" }
|
||||||
|
/* { dg-begin-multiline-output "" }
|
||||||
|
static_assert (foo::test<int>::value, "foo");
|
||||||
|
~~~~~~~~~~~~~~~~^~~~~
|
||||||
|
{ dg-end-multiline-output "" } */
|
||||||
|
|
||||||
|
static_assert (foo::test<int>::value && true, "bar"); // { dg-error "static assertion failed: bar" }
|
||||||
|
/* { dg-begin-multiline-output "" }
|
||||||
|
static_assert (foo::test<int>::value && true, "bar");
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
|
||||||
|
{ dg-end-multiline-output "" } */
|
|
@ -6,4 +6,4 @@ template <typename T> struct B {
|
||||||
};
|
};
|
||||||
struct D : B<int>, B<char> {};
|
struct D : B<int>, B<char> {};
|
||||||
|
|
||||||
int i2 = D::Bar(2); // { dg-error "10:reference to 'Bar' is ambiguous" }
|
int i2 = D::Bar(2); // { dg-error "13:reference to 'Bar' is ambiguous" }
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
2018-11-21 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
|
PR c++/87386
|
||||||
|
* testsuite/20_util/scoped_allocator/69293_neg.cc: Adjust expected
|
||||||
|
line.
|
||||||
|
* testsuite/20_util/uses_allocator/cons_neg.cc: Likewise.
|
||||||
|
* testsuite/20_util/uses_allocator/69293_neg.cc: Likewise.
|
||||||
|
* testsuite/experimental/propagate_const/requirements2.cc: Likewise.
|
||||||
|
* testsuite/experimental/propagate_const/requirements3.cc: Likewise.
|
||||||
|
* testsuite/experimental/propagate_const/requirements4.cc: Likewise.
|
||||||
|
* testsuite/experimental/propagate_const/requirements5.cc: Likewise.
|
||||||
|
|
||||||
2018-11-21 Jonathan Wakely <jwakely@redhat.com>
|
2018-11-21 Jonathan Wakely <jwakely@redhat.com>
|
||||||
|
|
||||||
PR libstdc++/88111
|
PR libstdc++/88111
|
||||||
|
|
|
@ -46,5 +46,5 @@ test01()
|
||||||
scoped_alloc sa;
|
scoped_alloc sa;
|
||||||
auto p = sa.allocate(1);
|
auto p = sa.allocate(1);
|
||||||
sa.construct(p); // this is required to be ill-formed
|
sa.construct(p); // this is required to be ill-formed
|
||||||
// { dg-error "static assertion failed" "" { target *-*-* } 94 }
|
// { dg-error "static assertion failed" "" { target *-*-* } 96 }
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,5 +44,5 @@ test01()
|
||||||
{
|
{
|
||||||
alloc_type a;
|
alloc_type a;
|
||||||
std::tuple<X> t(std::allocator_arg, a); // this is required to be ill-formed
|
std::tuple<X> t(std::allocator_arg, a); // this is required to be ill-formed
|
||||||
// { dg-error "static assertion failed" "" { target *-*-* } 94 }
|
// { dg-error "static assertion failed" "" { target *-*-* } 96 }
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,4 +43,4 @@ void test01()
|
||||||
|
|
||||||
tuple<Type> t(allocator_arg, a, 1);
|
tuple<Type> t(allocator_arg, a, 1);
|
||||||
}
|
}
|
||||||
// { dg-error "static assertion failed" "" { target *-*-* } 94 }
|
// { dg-error "static assertion failed" "" { target *-*-* } 96 }
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
using std::experimental::propagate_const;
|
using std::experimental::propagate_const;
|
||||||
|
|
||||||
// { dg-error "requires a class or a pointer to an object type" "" { target *-*-* } 105 }
|
// { dg-error "requires a class or a pointer to an object type" "" { target *-*-* } 107 }
|
||||||
// { dg-error "not a pointer-to-object type" "" { target *-*-* } 66 }
|
// { dg-error "not a pointer-to-object type" "" { target *-*-* } 66 }
|
||||||
// { dg-error "forming pointer to reference type" "" { target *-*-* } 187 }
|
// { dg-error "forming pointer to reference type" "" { target *-*-* } 187 }
|
||||||
// { dg-error "forming pointer to reference type" "" { target *-*-* } 213 }
|
// { dg-error "forming pointer to reference type" "" { target *-*-* } 213 }
|
||||||
|
|
|
@ -21,6 +21,6 @@
|
||||||
|
|
||||||
using std::experimental::propagate_const;
|
using std::experimental::propagate_const;
|
||||||
|
|
||||||
// { dg-error "requires a class or a pointer to an object type" "" { target *-*-* } 105 }
|
// { dg-error "requires a class or a pointer to an object type" "" { target *-*-* } 107 }
|
||||||
|
|
||||||
propagate_const<void (*)()> test1;
|
propagate_const<void (*)()> test1;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
using std::experimental::propagate_const;
|
using std::experimental::propagate_const;
|
||||||
|
|
||||||
// { dg-error "requires a class or a pointer to an object type" "" { target *-*-* } 105 }
|
// { dg-error "requires a class or a pointer to an object type" "" { target *-*-* } 107 }
|
||||||
// { dg-error "invalid type" "" { target *-*-* } 66 }
|
// { dg-error "invalid type" "" { target *-*-* } 66 }
|
||||||
// { dg-error "uninitialized reference member" "" { target *-*-* } 112 }
|
// { dg-error "uninitialized reference member" "" { target *-*-* } 112 }
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,6 @@
|
||||||
|
|
||||||
using std::experimental::propagate_const;
|
using std::experimental::propagate_const;
|
||||||
|
|
||||||
// { dg-error "requires a class or a pointer to an object type" "" { target *-*-* } 105 }
|
// { dg-error "requires a class or a pointer to an object type" "" { target *-*-* } 107 }
|
||||||
|
|
||||||
propagate_const<int[1]> test1;
|
propagate_const<int[1]> test1;
|
||||||
|
|
Loading…
Reference in New Issue