diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index f625b0a310c8fa084bcc8f8bc1ab4cd1e2f0e4ef..82f3903838e2cb71290a59acb0d6698951eb8c59 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -27721,11 +27721,20 @@ cp_parser_class_head (cp_parser* parser,
                          class_head_start_location,
                          get_finish (type_start_token->location));
       rich_location richloc (line_table, reported_loc);
-      richloc.add_fixit_insert_before (class_head_start_location,
-                                       "template <> ");
-      error_at (&richloc,
-		"an explicit specialization must be preceded by"
-		" %<template <>%>");
+      if (processing_explicit_instantiation)
+	{
+	  richloc.add_fixit_insert_before ("<> ");
+	  error_at (&richloc,
+		    "an explicit instantiation cannot have a definition;"
+		    " use %<template <>%> to declare a specialization");
+	}
+      else
+	{
+	  richloc.add_fixit_insert_before ("template <> ");
+	  error_at (&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.  */
diff --git a/gcc/testsuite/g++.dg/template/explicit-instantiation9.C b/gcc/testsuite/g++.dg/template/explicit-instantiation9.C
new file mode 100644
index 0000000000000000000000000000000000000000..c4400226ef835c2d1595b2d0ac851dd00efdca79
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/explicit-instantiation9.C
@@ -0,0 +1,6 @@
+// Fixits for specialisations are not valid for instantiations
+
+template <typename T>
+struct S {};
+
+template struct S<int> {};  // { dg-error "explicit instantiation cannot have a definition" }