+2016-05-02 David Malcolm <dmalcolm@redhat.com>
+
+ PR c++/62314
+ * parser.c (cp_parser_class_head): Capture the start location;
+ use it to emit a fix-it insertion hint when complaining
+ about missing "template <> " in explicit specializations.
+
2016-05-02 Richard Sandiford <richard.sandiford@arm.com>
* init.c (build_new_1): Use shift operators instead of wi:: shifts.
if (class_key == none_type)
return error_mark_node;
+ location_t class_head_start_location = input_location;
+
/* Parse the attributes. */
attributes = cp_parser_attributes_opt (parser);
&& parser->num_template_parameter_lists == 0
&& template_id_p)
{
- error_at (type_start_token->location,
- "an explicit specialization must be preceded by %<template <>%>");
+ /* Build a location of this form:
+ struct typename <ARGS>
+ ^~~~~~~~~~~~~~~~~~~~~~
+ with caret==start at the start token, and
+ finishing at the end of the type. */
+ location_t reported_loc
+ = make_location (class_head_start_location,
+ class_head_start_location,
+ get_finish (type_start_token->location));
+ rich_location richloc (line_table, reported_loc);
+ richloc.add_fixit_insert (class_head_start_location, "template <> ");
+ error_at_rich_loc
+ (&richloc,
+ "an explicit specialization must be preceded by %<template <>%>");
invalid_explicit_specialization_p = true;
/* Take the same action that would have been taken by
cp_parser_explicit_specialization. */
+2016-05-02 David Malcolm <dmalcolm@redhat.com>
+
+ PR c++/62314
+ * g++.dg/pr62314.C: New test case.
+
2016-05-02 Jan Hubicka <hubicka@ucw.cz>
* gcc.dg/ipa/inline-8.c: New testcase.
--- /dev/null
+// { dg-options "-fdiagnostics-show-caret" }
+
+template <typename T>
+struct iterator_traits {};
+
+struct file_iterator;
+
+struct iterator_traits<file_iterator> { // { dg-error "explicit specialization must be preceded by .template" }
+};
+
+/* Verify that we emit a fixit hint for this case. */
+
+/* { dg-begin-multiline-output "" }
+ struct iterator_traits<file_iterator>
+ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ template <>
+ { dg-end-multiline-output "" } */