aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2019-10-07 15:37:52 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2019-10-07 15:37:52 +0000
commit132235c30fbb2f660e93d72578e95aeb3c7a932f (patch)
tree05dde3d801b7de601074260a0bb131024753a7bf
parentdcd2ca63ec5c467decb70db983fc19a8329f67dc (diff)
downloadgcc-132235c30fbb2f660e93d72578e95aeb3c7a932f.zip
gcc-132235c30fbb2f660e93d72578e95aeb3c7a932f.tar.gz
gcc-132235c30fbb2f660e93d72578e95aeb3c7a932f.tar.bz2
call.c (resolve_args): Use cp_expr_loc_or_input_loc in one place.
/cp 2019-10-07 Paolo Carlini <paolo.carlini@oracle.com> * call.c (resolve_args): Use cp_expr_loc_or_input_loc in one place. * decl.c (grokdeclarator): Use id_loc in one place. * decl2.c (build_anon_union_vars): Use DECL_SOURCE_LOCATION. * parser.c (cp_parser_delete_expression): Fix the location of the returned expression. (cp_parser_throw_expression): Likewise. * pt.c (determine_specialization): Use DECL_SOURCE_LOCATION. /testsuite 2019-10-07 Paolo Carlini <paolo.carlini@oracle.com> * g++.dg/diagnostic/not-a-function-template-1.C: New. * g++.dg/template/crash107.C: Adjust expected location. * g++.dg/template/dependent-expr1.C: Check locations. * g++.dg/template/error17.C: Check location. From-SVN: r276661
-rw-r--r--gcc/cp/ChangeLog10
-rw-r--r--gcc/cp/call.c3
-rw-r--r--gcc/cp/decl.c4
-rw-r--r--gcc/cp/decl2.c3
-rw-r--r--gcc/cp/parser.c28
-rw-r--r--gcc/cp/pt.c6
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/g++.dg/diagnostic/not-a-function-template-1.C9
-rw-r--r--gcc/testsuite/g++.dg/template/crash107.C4
-rw-r--r--gcc/testsuite/g++.dg/template/dependent-expr1.C8
-rw-r--r--gcc/testsuite/g++.dg/template/error17.C2
11 files changed, 68 insertions, 16 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index b40825e..90cab94 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,13 @@
+2019-10-07 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * call.c (resolve_args): Use cp_expr_loc_or_input_loc in one place.
+ * decl.c (grokdeclarator): Use id_loc in one place.
+ * decl2.c (build_anon_union_vars): Use DECL_SOURCE_LOCATION.
+ * parser.c (cp_parser_delete_expression): Fix the location of the
+ returned expression.
+ (cp_parser_throw_expression): Likewise.
+ * pt.c (determine_specialization): Use DECL_SOURCE_LOCATION.
+
2019-10-05 Jakub Jelinek <jakub@redhat.com>
PR c++/91369 - Implement P0784R7: constexpr new
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 56dcbd3..6c9acac 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4381,7 +4381,8 @@ resolve_args (vec<tree, va_gc> *args, tsubst_flags_t complain)
else if (VOID_TYPE_P (TREE_TYPE (arg)))
{
if (complain & tf_error)
- error ("invalid use of void expression");
+ error_at (cp_expr_loc_or_input_loc (arg),
+ "invalid use of void expression");
return NULL;
}
else if (invalid_nonstatic_memfn_p (EXPR_LOCATION (arg), arg, complain))
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index ea9a001..e405367 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -12754,8 +12754,8 @@ grokdeclarator (const cp_declarator *declarator,
tree tmpl = TREE_OPERAND (unqualified_id, 0);
if (variable_template_p (tmpl))
{
- error ("specialization of variable template %qD "
- "declared as function", tmpl);
+ error_at (id_loc, "specialization of variable template "
+ "%qD declared as function", tmpl);
inform (DECL_SOURCE_LOCATION (tmpl),
"variable template declared here");
return error_mark_node;
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 8f935e8..a28e776 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -1608,7 +1608,8 @@ build_anon_union_vars (tree type, tree object)
just give an error. */
if (TREE_CODE (type) != UNION_TYPE)
{
- error ("anonymous struct not inside named type");
+ error_at (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
+ "anonymous struct not inside named type");
return error_mark_node;
}
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 018a03d..c61e0b2 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -9014,6 +9014,7 @@ cp_parser_delete_expression (cp_parser* parser)
bool global_scope_p;
bool array_p;
tree expression;
+ location_t start_loc = cp_lexer_peek_token (parser->lexer)->location;
/* Look for the optional `::' operator. */
global_scope_p
@@ -9043,8 +9044,18 @@ cp_parser_delete_expression (cp_parser* parser)
if (cp_parser_non_integral_constant_expression (parser, NIC_DEL))
return error_mark_node;
- return delete_sanity (expression, NULL_TREE, array_p, global_scope_p,
- tf_warning_or_error);
+ /* Construct a location e.g.:
+ delete [ ] ptr
+ ^~~~~~~~~~~~~~
+ with caret == start at the start of the "delete" token, and
+ the end at the end of the final token we consumed. */
+ location_t combined_loc = make_location (start_loc, start_loc,
+ parser->lexer);
+ expression = delete_sanity (expression, NULL_TREE, array_p,
+ global_scope_p, tf_warning_or_error);
+ protected_set_expr_location (expression, combined_loc);
+
+ return expression;
}
/* Returns 1 if TOKEN may start a cast-expression and isn't '++', '--',
@@ -25827,6 +25838,7 @@ cp_parser_throw_expression (cp_parser* parser)
{
tree expression;
cp_token* token;
+ location_t start_loc = cp_lexer_peek_token (parser->lexer)->location;
cp_parser_require_keyword (parser, RID_THROW, RT_THROW);
token = cp_lexer_peek_token (parser->lexer);
@@ -25842,7 +25854,17 @@ cp_parser_throw_expression (cp_parser* parser)
else
expression = cp_parser_assignment_expression (parser);
- return build_throw (expression);
+ /* Construct a location e.g.:
+ throw x
+ ^~~~~~~
+ with caret == start at the start of the "throw" token, and
+ the end at the end of the final token we consumed. */
+ location_t combined_loc = make_location (start_loc, start_loc,
+ parser->lexer);
+ expression = build_throw (expression);
+ protected_set_expr_location (expression, combined_loc);
+
+ return expression;
}
/* GNU Extensions */
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 67b3b63..6310e7b 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -2137,7 +2137,8 @@ determine_specialization (tree template_id,
if (TREE_CODE (decl) == FUNCTION_DECL && !is_overloaded_fn (fns))
{
- error ("%qD is not a function template", fns);
+ error_at (DECL_SOURCE_LOCATION (decl),
+ "%qD is not a function template", fns);
return error_mark_node;
}
else if (VAR_P (decl) && !variable_template_p (fns))
@@ -2416,7 +2417,8 @@ determine_specialization (tree template_id,
error ("template-id %qD for %q+D does not match any template "
"declaration", template_id, decl);
if (header_count && header_count != template_count + 1)
- inform (input_location, "saw %d %<template<>%>, need %d for "
+ inform (DECL_SOURCE_LOCATION (decl),
+ "saw %d %<template<>%>, need %d for "
"specializing a member function template",
header_count, template_count + 1);
else
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 01253be..e851acd 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2019-10-07 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * g++.dg/diagnostic/not-a-function-template-1.C: New.
+ * g++.dg/template/crash107.C: Adjust expected location.
+ * g++.dg/template/dependent-expr1.C: Check locations.
+ * g++.dg/template/error17.C: Check location.
+
2019-10-07 Richard Sandiford <richard.sandiford@arm.com>
PR target/91994
diff --git a/gcc/testsuite/g++.dg/diagnostic/not-a-function-template-1.C b/gcc/testsuite/g++.dg/diagnostic/not-a-function-template-1.C
new file mode 100644
index 0000000..caf8afa
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/not-a-function-template-1.C
@@ -0,0 +1,9 @@
+// { dg-do compile { target c++14 } }
+
+template<typename> int A; // { dg-message "24:variable template" }
+
+template int A<>(); // { dg-error "14:template<class>" }
+
+struct B {
+ friend int A<>(); // { dg-error "14:specialization" }
+};
diff --git a/gcc/testsuite/g++.dg/template/crash107.C b/gcc/testsuite/g++.dg/template/crash107.C
index cecf901..3b0b4e8 100644
--- a/gcc/testsuite/g++.dg/template/crash107.C
+++ b/gcc/testsuite/g++.dg/template/crash107.C
@@ -6,8 +6,8 @@
template<typename FP_> struct Vec { // { dg-message "note" }
Vec& operator^=(Vec& rhs) {
union {
- struct {FP_ x,y,z;};
- }; // { dg-error "anonymous struct" }
+ struct {FP_ x,y,z;}; // { dg-error "20:anonymous struct" }
+ };
X = y*rhs.z() - z*rhs.y(); // { dg-error "not declared|no member" }
}
Vec& operator^(Vec& rhs) {
diff --git a/gcc/testsuite/g++.dg/template/dependent-expr1.C b/gcc/testsuite/g++.dg/template/dependent-expr1.C
index 7964986..eda7526 100644
--- a/gcc/testsuite/g++.dg/template/dependent-expr1.C
+++ b/gcc/testsuite/g++.dg/template/dependent-expr1.C
@@ -19,11 +19,11 @@ namespace std
Foo (sizeof (x));
Foo (__alignof__ (I));
Foo (__alignof__ (x));
- Foo (x->~I ()); // { dg-error "" }
+ Foo (x->~I ()); // { dg-error "16:invalid" }
// Foo (typeid (I));
- Foo (delete x); // { dg-error "" }
- Foo (delete[] x); // { dg-error "" }
- Foo (throw x); // { dg-error "" }
+ Foo (delete x); // { dg-error "10:invalid" }
+ Foo (delete[] x); // { dg-error "10:invalid" }
+ Foo (throw x); // { dg-error "10:invalid" }
}
}
diff --git a/gcc/testsuite/g++.dg/template/error17.C b/gcc/testsuite/g++.dg/template/error17.C
index 30a693f..5b3281a 100644
--- a/gcc/testsuite/g++.dg/template/error17.C
+++ b/gcc/testsuite/g++.dg/template/error17.C
@@ -5,5 +5,5 @@ void
foo()
{
union { struct { }; }; // { dg-error "prohibits anonymous struct" "anon" }
- // { dg-error "not inside" "not inside" { target *-*-* } .-1 }
+ // { dg-error "18:anonymous struct not inside" "not inside" { target *-*-* } .-1 }
}