From 1d9b478e10a9995f1a4c40a6d9b5f54c987ffbdf Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 18 Jul 2025 11:42:39 -0400
Subject: [PATCH 39/41] {needs ChangeLog} convert diagnostic_t to enum class
 diagnostics::kind

---
 gcc/Makefile.in                               |   2 +-
 gcc/ada/gcc-interface/trans.cc                |  10 +-
 gcc/analyzer/pending-diagnostic.cc            |   4 +-
 gcc/analyzer/program-point.cc                 |   2 +-
 gcc/c-family/c-common.cc                      |  14 +-
 gcc/c-family/c-format.cc                      |   4 +-
 gcc/c-family/c-lex.cc                         |   2 +-
 gcc/c-family/c-opts.cc                        |   2 +-
 gcc/c-family/c-pragma.cc                      |  15 +-
 gcc/c-family/c-warn.cc                        |   4 +-
 gcc/c/c-errors.cc                             |  27 ++-
 gcc/c/c-parser.cc                             |   7 +-
 gcc/c/c-typeck.cc                             |  25 ++-
 gcc/cobol/util.cc                             |  26 +--
 gcc/config/aarch64/aarch64.cc                 |   5 +-
 gcc/config/i386/i386-options.cc               |   4 +-
 gcc/config/s390/s390.cc                       |  10 +-
 gcc/cp/call.cc                                |  24 +--
 gcc/cp/constexpr.cc                           |   7 +-
 gcc/cp/cp-tree.h                              |   6 +-
 gcc/cp/decl.cc                                |  44 +++--
 gcc/cp/error.cc                               |  12 +-
 gcc/cp/init.cc                                |   6 +-
 gcc/cp/method.cc                              |  19 +-
 gcc/cp/module.cc                              |  34 ++--
 gcc/cp/parser.cc                              |  38 ++--
 gcc/cp/pt.cc                                  |   4 +-
 gcc/cp/semantics.cc                           |   3 +-
 gcc/cp/typeck.cc                              |  15 +-
 gcc/cp/typeck2.cc                             |  15 +-
 gcc/d/d-diagnostic.cc                         |  19 +-
 gcc/diagnostic-core.h                         |  24 +--
 gcc/diagnostic-global-context.cc              |  77 +++++---
 gcc/diagnostic.cc                             | 165 +++++++++---------
 gcc/diagnostic.h                              |  26 ++-
 gcc/diagnostics/buffering.cc                  |   6 +-
 gcc/diagnostics/buffering.h                   |   2 +-
 gcc/diagnostics/context.h                     |  47 ++---
 gcc/diagnostics/diagnostic-info.h             |   4 +-
 gcc/diagnostics/html-sink.cc                  |  60 +++----
 gcc/{diagnostic.def => diagnostics/kinds.def} |  40 ++---
 gcc/diagnostics/kinds.h                       |  45 +++++
 gcc/diagnostics/lazy-paths.cc                 |   8 +-
 gcc/diagnostics/option-classifier.cc          |  38 ++--
 gcc/diagnostics/option-classifier.h           |  20 +--
 gcc/diagnostics/output-spec.h                 |   2 +-
 gcc/diagnostics/paths-output.cc               |   4 +-
 gcc/diagnostics/sarif-sink.cc                 |  94 +++++-----
 gcc/diagnostics/selftest-context.cc           |   4 +-
 gcc/diagnostics/selftest-context.h            |   2 +-
 gcc/diagnostics/sink.h                        |   2 +-
 gcc/diagnostics/source-printing.cc            |  41 ++---
 gcc/diagnostics/text-sink.cc                  |  27 ++-
 gcc/diagnostics/text-sink.h                   |   4 +-
 gcc/fortran/cpp.cc                            |  14 +-
 gcc/fortran/error.cc                          |  34 ++--
 gcc/fortran/options.cc                        |   3 +-
 gcc/gcc.cc                                    |   3 +-
 gcc/jit/dummy-frontend.cc                     |   4 +-
 gcc/libgdiagnostics.cc                        |  15 +-
 gcc/lto-wrapper.cc                            |   4 +-
 gcc/m2/gm2-gcc/m2linemap.cc                   |   9 +-
 gcc/m2/gm2-gcc/rtegraph.cc                    |  14 +-
 gcc/opts-common.cc                            |  19 +-
 gcc/opts-diagnostic.h                         |   7 +-
 gcc/opts.cc                                   |  33 ++--
 gcc/rtl-error.cc                              |   8 +-
 gcc/rust/backend/rust-tree.cc                 |  12 +-
 gcc/rust/backend/rust-tree.h                  |   6 +-
 gcc/rust/resolve/rust-ast-resolve-expr.cc     |   2 +-
 gcc/rust/resolve/rust-ice-finalizer.cc        |   4 +-
 gcc/rust/resolve/rust-ice-finalizer.h         |   2 +-
 .../resolve/rust-late-name-resolver-2.0.cc    |   2 +-
 gcc/substring-locations.cc                    |   4 +-
 .../diagnostic_plugin_test_show_locus.cc      |   2 +-
 .../plugin/expensive_selftests_plugin.cc      |   3 +-
 .../gcc.dg/plugin/location_overflow_plugin.cc |   4 +-
 gcc/testsuite/lib/gcc-dg.exp                  |   4 +-
 gcc/toplev.cc                                 |   6 +-
 libcpp/internal.h                             |   4 +-
 80 files changed, 770 insertions(+), 603 deletions(-)
 rename gcc/{diagnostic.def => diagnostics/kinds.def} (53%)
 create mode 100644 gcc/diagnostics/kinds.h

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index d11277786a5b..e283cd316c04 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1069,7 +1069,7 @@ TREE_SSA_H = tree-ssa.h tree-ssa-operands.h \
 PRETTY_PRINT_H = pretty-print.h $(INPUT_H) $(OBSTACK_H) wide-int-print.h
 TREE_PRETTY_PRINT_H = tree-pretty-print.h $(PRETTY_PRINT_H)
 GIMPLE_PRETTY_PRINT_H = gimple-pretty-print.h $(TREE_PRETTY_PRINT_H)
-DIAGNOSTIC_CORE_H = diagnostic-core.h $(INPUT_H) bversion.h diagnostic.def
+DIAGNOSTIC_CORE_H = diagnostic-core.h $(INPUT_H) bversion.h diagnostics/kinds.def
 DIAGNOSTIC_H = diagnostic.h $(DIAGNOSTIC_CORE_H) $(PRETTY_PRINT_H)
 C_PRETTY_PRINT_H = c-family/c-pretty-print.h $(PRETTY_PRINT_H) \
 	$(C_COMMON_H) $(TREE_H)
diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc
index 23fc814f9dec..235d74ccfece 100644
--- a/gcc/ada/gcc-interface/trans.cc
+++ b/gcc/ada/gcc-interface/trans.cc
@@ -1521,12 +1521,12 @@ Pragma_to_gnu (Node_Id gnat_node)
 	    switch (id)
 	      {
 	      case Pragma_Warning_As_Error:
-		kind = DK_ERROR;
+		kind = diagnostics::kind::error;
 		imply = false;
 		break;
 
 	      case Pragma_Warnings:
-		kind = DK_WARNING;
+		kind = diagnostics::kind::warning;
 		imply = true;
 		break;
 
@@ -1543,11 +1543,11 @@ Pragma_to_gnu (Node_Id gnat_node)
 	    switch (Chars (Expression (gnat_temp)))
 	      {
 		case Name_Off:
-		  kind = DK_IGNORED;
+		  kind = diagnostics::kind::ignored;
 		  break;
 
 		case Name_On:
-		  kind = DK_WARNING;
+		  kind = diagnostics::kind::warning;
 		  break;
 
 		default:
@@ -1569,7 +1569,7 @@ Pragma_to_gnu (Node_Id gnat_node)
 		gnat_expr = Empty;
 
 		/* For pragma Warnings (Off), we save the current state...  */
-		if (kind == DK_IGNORED)
+		if (kind == diagnostics::kind::ignored)
 		  diagnostic_push_diagnostics (global_dc, location);
 
 		/* ...so that, for pragma Warnings (On), we do not enable all
diff --git a/gcc/analyzer/pending-diagnostic.cc b/gcc/analyzer/pending-diagnostic.cc
index 20312d4d21d6..cc2d7959c4cc 100644
--- a/gcc/analyzer/pending-diagnostic.cc
+++ b/gcc/analyzer/pending-diagnostic.cc
@@ -92,7 +92,7 @@ diagnostic_emission_context::warn (const char *gmsgid, ...)
   auto_diagnostic_group d;
   va_list ap;
   va_start (ap, gmsgid);
-  const bool result = emit_diagnostic_valist_meta (DK_WARNING,
+  const bool result = emit_diagnostic_valist_meta (diagnostics::kind::warning,
 						   &m_rich_loc, &m_metadata,
 						   pd.get_controlling_option (),
 						   gmsgid, &ap);
@@ -110,7 +110,7 @@ diagnostic_emission_context::inform (const char *gmsgid, ...)
   auto_diagnostic_group d;
   va_list ap;
   va_start (ap, gmsgid);
-  emit_diagnostic_valist_meta (DK_NOTE,
+  emit_diagnostic_valist_meta (diagnostics::kind::note,
 			       &m_rich_loc, &m_metadata,
 			       pd.get_controlling_option (),
 			       gmsgid, &ap);
diff --git a/gcc/analyzer/program-point.cc b/gcc/analyzer/program-point.cc
index 1d5d65c5cc40..a07d3c80a34d 100644
--- a/gcc/analyzer/program-point.cc
+++ b/gcc/analyzer/program-point.cc
@@ -265,7 +265,7 @@ function_point::print_source_line (pretty_printer *pp) const
   gcc_rich_location richloc (stmt->location);
   diagnostics::source_print_policy source_policy (tmp_dc);
   gcc_assert (pp);
-  source_policy.print (*pp, richloc, DK_ERROR, nullptr);
+  source_policy.print (*pp, richloc, diagnostics::kind::error, nullptr);
   pp_string (pp, pp_formatted_text (tmp_dc.get_reference_printer ()));
 }
 
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index 5f056402c2f9..147a3f35aee0 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -7047,7 +7047,7 @@ c_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED,
 		  const char *msg, va_list *ap)
 {
   diagnostic_info diagnostic;
-  diagnostic_t dlevel;
+  enum diagnostics::kind dlevel;
   bool save_warn_system_headers = global_dc->m_warn_system_headers;
   bool ret;
 
@@ -7061,24 +7061,24 @@ c_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED,
     case CPP_DL_WARNING:
       if (flag_no_output)
 	return false;
-      dlevel = DK_WARNING;
+      dlevel = diagnostics::kind::warning;
       break;
     case CPP_DL_PEDWARN:
       if (flag_no_output && !flag_pedantic_errors)
 	return false;
-      dlevel = DK_PEDWARN;
+      dlevel = diagnostics::kind::pedwarn;
       break;
     case CPP_DL_ERROR:
-      dlevel = DK_ERROR;
+      dlevel = diagnostics::kind::error;
       break;
     case CPP_DL_ICE:
-      dlevel = DK_ICE;
+      dlevel = diagnostics::kind::ice;
       break;
     case CPP_DL_NOTE:
-      dlevel = DK_NOTE;
+      dlevel = diagnostics::kind::note;
       break;
     case CPP_DL_FATAL:
-      dlevel = DK_FATAL;
+      dlevel = diagnostics::kind::fatal;
       break;
     default:
       gcc_unreachable ();
diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc
index 310cf752dbf3..a34f5d90b7ab 100644
--- a/gcc/c-family/c-format.cc
+++ b/gcc/c-family/c-format.cc
@@ -5580,7 +5580,9 @@ test_type_mismatch_range_labels ()
   diagnostics::selftest::test_context dc;
   diagnostic_show_locus (&dc,
 			 dc.m_source_printing,
-			 &richloc, DK_ERROR, dc.get_reference_printer ());
+			 &richloc,
+			 diagnostics::kind::error,
+			 dc.get_reference_printer ());
   if (c_dialect_cxx ())
     /* "char*", without a space.  */
     ASSERT_STREQ ("   printf (\"msg: %i\\n\", msg);\n"
diff --git a/gcc/c-family/c-lex.cc b/gcc/c-family/c-lex.cc
index fef6ae6f457b..b45d7228c5d2 100644
--- a/gcc/c-family/c-lex.cc
+++ b/gcc/c-family/c-lex.cc
@@ -1176,7 +1176,7 @@ interpret_integer (const cpp_token *token, unsigned int flags,
 	  && (flags & CPP_N_WIDTH) != CPP_N_LARGE)
 	emit_diagnostic
 	  ((c_dialect_cxx () ? cxx_dialect == cxx98 : !flag_isoc99)
-	   ? DK_PEDWARN : DK_WARNING,
+	   ? diagnostics::kind::pedwarn : diagnostics::kind::warning,
 	   input_location, OPT_Wlong_long,
 	   (flags & CPP_N_UNSIGNED)
 	   ? "integer constant is too large for %<unsigned long%> type"
diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index 6c68efd55d70..de70e47b576d 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -171,7 +171,7 @@ c_common_option_lang_mask (void)
 static void
 c_diagnostic_text_finalizer (diagnostics::text_sink &text_output,
 			     const diagnostic_info *diagnostic,
-			     diagnostic_t)
+			     enum diagnostics::kind)
 {
   pretty_printer *const pp = text_output.get_printer ();
   char *saved_prefix = pp_take_prefix (pp);
diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc
index 137b83bf5b15..8a1218bce71f 100644
--- a/gcc/c-family/c-pragma.cc
+++ b/gcc/c-family/c-pragma.cc
@@ -781,7 +781,7 @@ public:
       PK_IGNORED_ATTRIBUTES,
       PK_DIAGNOSTIC,
     } pd_kind;
-  diagnostic_t diagnostic_kind;
+  enum diagnostics::kind diagnostic_kind;
   const char *kind_str;
   const char *option_str;
   bool own_option_str;
@@ -792,7 +792,7 @@ public:
     valid = false;
     loc_kind = loc_option = UNKNOWN_LOCATION;
     pd_kind = PK_INVALID;
-    diagnostic_kind = DK_UNSPECIFIED;
+    diagnostic_kind = diagnostics::kind::unspecified;
     kind_str = option_str = nullptr;
     own_option_str = false;
   }
@@ -808,7 +808,7 @@ public:
     kind_str = kind_string;
 
     pd_kind = PK_INVALID;
-    diagnostic_kind = DK_UNSPECIFIED;
+    diagnostic_kind = diagnostics::kind::unspecified;
     if (strcmp (kind_str, "push") == 0)
       pd_kind = PK_PUSH;
     else if (strcmp (kind_str, "pop") == 0)
@@ -818,17 +818,17 @@ public:
     else if (strcmp (kind_str, "error") == 0)
       {
 	pd_kind = PK_DIAGNOSTIC;
-	diagnostic_kind = DK_ERROR;
+	diagnostic_kind = diagnostics::kind::error;
       }
     else if (strcmp (kind_str, "warning") == 0)
       {
 	pd_kind = PK_DIAGNOSTIC;
-	diagnostic_kind = DK_WARNING;
+	diagnostic_kind = diagnostics::kind::warning;
       }
     else if (strcmp (kind_str, "ignored") == 0)
       {
 	pd_kind = PK_DIAGNOSTIC;
-	diagnostic_kind = DK_IGNORED;
+	diagnostic_kind = diagnostics::kind::ignored;
       }
   }
 
@@ -1016,7 +1016,8 @@ handle_pragma_diagnostic_impl ()
      what we used to do here before and changing it breaks e.g.
      PR69543 and PR69558.  */
   control_warning_option (option_index, (int) data.diagnostic_kind,
-			  arg, data.diagnostic_kind != DK_IGNORED,
+			  arg,
+			  data.diagnostic_kind != diagnostics::kind::ignored,
 			  input_location, lang_mask, &handlers,
 			  &global_options, &global_options_set,
 			  global_dc);
diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc
index d547b08f55da..09517d28ba11 100644
--- a/gcc/c-family/c-warn.cc
+++ b/gcc/c-family/c-warn.cc
@@ -3835,7 +3835,7 @@ do_warn_array_compare (location_t location, tree_code code, tree op0, tree op1)
     op1 = TREE_OPERAND (op1, 0);
 
   auto_diagnostic_group d;
-  diagnostic_t kind = DK_WARNING;
+  enum diagnostics::kind kind = diagnostics::kind::warning;
   const char *msg;
   if (c_dialect_cxx () && cxx_dialect >= cxx20)
     {
@@ -3843,7 +3843,7 @@ do_warn_array_compare (location_t location, tree_code code, tree op0, tree op1)
       if (cxx_dialect >= cxx26)
 	{
 	  msg = G_("comparison between two arrays is not allowed in C++26");
-	  kind = DK_PERMERROR;
+	  kind = diagnostics::kind::permerror;
 	}
       else
 	msg = G_("comparison between two arrays is deprecated in C++20");
diff --git a/gcc/c/c-errors.cc b/gcc/c/c-errors.cc
index e91cafba56be..39ec1304766d 100644
--- a/gcc/c/c-errors.cc
+++ b/gcc/c/c-errors.cc
@@ -48,7 +48,8 @@ pedwarn_c23 (location_t location,
     {
       diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
 			   (pedantic && !flag_isoc2y)
-			   ? DK_PEDWARN : DK_WARNING);
+			   ? diagnostics::kind::pedwarn
+			   : diagnostics::kind::warning);
       diagnostic.m_option_id = OPT_Wc23_c2y_compat;
       warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
     }
@@ -58,7 +59,8 @@ pedwarn_c23 (location_t location,
   /* For -pedantic outside C2Y, issue a pedwarn.  */
   else if (pedantic && !flag_isoc2y)
     {
-      diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
+      diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
+			   diagnostics::kind::pedwarn);
       diagnostic.m_option_id = option_id;
       warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
     }
@@ -93,7 +95,8 @@ pedwarn_c11 (location_t location,
     {
       diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
 			   (pedantic && !flag_isoc23)
-			   ? DK_PEDWARN : DK_WARNING);
+			   ? diagnostics::kind::pedwarn
+			   : diagnostics::kind::warning);
       if (option_id == OPT_Wpedantic)
 	diagnostic.m_option_id = OPT_Wc11_c23_compat;
       else
@@ -106,7 +109,8 @@ pedwarn_c11 (location_t location,
   /* For -pedantic outside C23, issue a pedwarn.  */
   else if (pedantic && !flag_isoc23)
     {
-      diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
+      diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
+			   diagnostics::kind::pedwarn);
       diagnostic.m_option_id = option_id;
       warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
     }
@@ -137,7 +141,8 @@ pedwarn_c99 (location_t location,
     {
       diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
 			   (pedantic && !flag_isoc11)
-			   ? DK_PEDWARN : DK_WARNING);
+			   ? diagnostics::kind::pedwarn
+			   : diagnostics::kind::warning);
       diagnostic.m_option_id = OPT_Wc99_c11_compat;
       warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
     }
@@ -147,7 +152,8 @@ pedwarn_c99 (location_t location,
   /* For -pedantic outside C11, issue a pedwarn.  */
   else if (pedantic && !flag_isoc11)
     {
-      diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
+      diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
+			   diagnostics::kind::pedwarn);
       diagnostic.m_option_id = option_id;
       warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
     }
@@ -183,7 +189,8 @@ pedwarn_c90 (location_t location,
 	{
 	  diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
 			       (pedantic && !flag_isoc99)
-			       ? DK_PEDWARN : DK_WARNING);
+			       ? diagnostics::kind::pedwarn
+			       : diagnostics::kind::warning);
 	  diagnostic.m_option_id = option_id;
 	  diagnostic_report_diagnostic (global_dc, &diagnostic);
 	  warned = true;
@@ -196,7 +203,8 @@ pedwarn_c90 (location_t location,
     {
       diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
 			   (pedantic && !flag_isoc99)
-			   ? DK_PEDWARN : DK_WARNING);
+			   ? diagnostics::kind::pedwarn
+			   : diagnostics::kind::warning);
       diagnostic.m_option_id = OPT_Wc90_c99_compat;
       diagnostic_report_diagnostic (global_dc, &diagnostic);
     }
@@ -206,7 +214,8 @@ pedwarn_c90 (location_t location,
   /* For -pedantic outside C99, issue a pedwarn.  */
   else if (pedantic && !flag_isoc99)
     {
-      diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
+      diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
+			   diagnostics::kind::pedwarn);
       diagnostic.m_option_id = option_id;
       diagnostic_report_diagnostic (global_dc, &diagnostic);
       warned = true;
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 0c3e3e2889c6..1f95b7566597 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -29126,11 +29126,14 @@ c_parser_omp_error (c_parser *parser, enum pragma_context context)
       if (msg == NULL)
 	msg = _("<message unknown at compile time>");
     }
+  const enum diagnostics::kind diag_kind = (severity_fatal
+					    ? diagnostics::kind::error
+					    : diagnostics::kind::warning);
   if (msg)
-    emit_diagnostic (severity_fatal ? DK_ERROR : DK_WARNING, loc, 0,
+    emit_diagnostic (diag_kind, loc, 0,
 		     "%<pragma omp error%> encountered: %s", msg);
   else
-    emit_diagnostic (severity_fatal ? DK_ERROR : DK_WARNING, loc, 0,
+    emit_diagnostic (diag_kind, loc, 0,
 		     "%<pragma omp error%> encountered");
   return false;
 }
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 794810640e82..fe6c9d947354 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -6437,14 +6437,16 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
       else
 	{
 	  int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
-	  diagnostic_t kind = DK_PERMERROR;
+	  enum diagnostics::kind kind = diagnostics::kind::permerror;
 	  if (!flag_isoc99)
 	    /* This downgrade to a warning ensures that -std=gnu89
 	       -pedantic-errors does not flag these mismatches between
-	       builtins as errors (as DK_PERMERROR would).  ISO C99
-	       and later do not have implicit function declarations,
+	       builtins as errors (as diagnostics::kind::permerror would)
+	       ISO C99 and later do not have implicit function declarations,
 	       so the mismatch cannot occur naturally there.  */
-	    kind = bltin1 && bltin2 ? DK_WARNING : DK_PEDWARN;
+	    kind = (bltin1 && bltin2
+		    ? diagnostics::kind::warning
+		    : diagnostics::kind::pedwarn);
 	  if (emit_diagnostic (kind, colon_loc, OPT_Wincompatible_pointer_types,
 			       "pointer type mismatch "
 			       "in conditional expression"))
@@ -7589,7 +7591,8 @@ error_init (location_t loc, const char *gmsgid, ...)
   /* The gmsgid may be a format string with %< and %>. */
   va_list ap;
   va_start (ap, gmsgid);
-  bool warned = emit_diagnostic_valist (DK_ERROR, loc, -1, gmsgid, &ap);
+  bool warned = emit_diagnostic_valist (diagnostics::kind::error,
+					loc, -1, gmsgid, &ap);
   va_end (ap);
 
   ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
@@ -7601,7 +7604,7 @@ error_init (location_t loc, const char *gmsgid, ...)
 
 static bool ATTRIBUTE_GCC_DIAG (3,0)
 pedwarn_permerror_init (location_t loc, int opt, const char *gmsgid,
-			va_list *ap, diagnostic_t kind)
+			va_list *ap, enum diagnostics::kind kind)
 {
   /* Use the location where a macro was expanded rather than where
      it was defined to make sure macros defined in system headers
@@ -7628,7 +7631,8 @@ pedwarn_init (location_t loc, int opt, const char *gmsgid, ...)
 {
   va_list ap;
   va_start (ap, gmsgid);
-  bool warned = pedwarn_permerror_init (loc, opt, gmsgid, &ap, DK_PEDWARN);
+  bool warned = pedwarn_permerror_init (loc, opt, gmsgid, &ap,
+					diagnostics::kind::pedwarn);
   va_end (ap);
   return warned;
 }
@@ -7640,7 +7644,8 @@ permerror_init (location_t loc, int opt, const char *gmsgid, ...)
 {
   va_list ap;
   va_start (ap, gmsgid);
-  bool warned = pedwarn_permerror_init (loc, opt, gmsgid, &ap, DK_PERMERROR);
+  bool warned = pedwarn_permerror_init (loc, opt, gmsgid, &ap,
+					diagnostics::kind::permerror);
   va_end (ap);
   return warned;
 }
@@ -12880,7 +12885,9 @@ c_finish_return (location_t loc, tree retval, tree origtype, bool musttail_p)
 	  && valtype != NULL_TREE && TREE_CODE (valtype) != VOID_TYPE)
 	{
 	  no_warning = true;
-	  if (emit_diagnostic (flag_isoc99 ? DK_PERMERROR : DK_WARNING,
+	  if (emit_diagnostic (flag_isoc99
+			       ? diagnostics::kind::permerror
+			       : diagnostics::kind::warning,
 			       loc, OPT_Wreturn_mismatch,
 			       "%<return%> with no value,"
 			       " in function returning non-void"))
diff --git a/gcc/cobol/util.cc b/gcc/cobol/util.cc
index e30cd6c6f22b..afac326a9d95 100644
--- a/gcc/cobol/util.cc
+++ b/gcc/cobol/util.cc
@@ -1977,7 +1977,7 @@ ydferror( const char gmsgid[], ... ) {
   va_start (ap, gmsgid);
   rich_location richloc (line_table, token_location);
   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_zero,
-                                         gmsgid, &ap, DK_ERROR);
+                                         gmsgid, &ap, diagnostics::kind::error);
   va_end (ap);
 }
 
@@ -2035,7 +2035,7 @@ class temp_loc_t {
   va_start (ap, gmsgid);                                                \
   rich_location richloc (line_table, token_location);                   \
   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_zero,        \
-                                         gmsgid, &ap, DK_ERROR);        \
+                                         gmsgid, &ap, diagnostics::kind::error);        \
   va_end (ap);                                                          \
   global_dc->end_group();
 
@@ -2061,7 +2061,7 @@ yyerror( const char gmsgid[], ... ) {
   va_start (ap, gmsgid);
   rich_location richloc (line_table, token_location);
   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_zero,
-                                         gmsgid, &ap, DK_ERROR);
+                                         gmsgid, &ap, diagnostics::kind::error);
   va_end (ap);
   global_dc->end_group();
 }
@@ -2072,7 +2072,7 @@ yywarn( const char gmsgid[], ... ) {
   auto_diagnostic_group d;
   va_list ap;
   va_start (ap, gmsgid);
-  auto ret = emit_diagnostic_valist( DK_WARNING, token_location,
+  auto ret = emit_diagnostic_valist( diagnostics::kind::warning, token_location,
                                      option_zero, gmsgid, &ap );
   va_end (ap);
   return ret;
@@ -2270,7 +2270,8 @@ cbl_internal_error(const char *gmsgid, ...) {
   auto_diagnostic_group d;
   va_list ap;
   va_start(ap, gmsgid);
-  emit_diagnostic_valist( DK_ICE, token_location, option_zero, gmsgid, &ap );
+  emit_diagnostic_valist( diagnostics::kind::ice,
+			  token_location, option_zero, gmsgid, &ap );
   va_end(ap);
 }
 
@@ -2280,7 +2281,8 @@ cbl_unimplementedw(const char *gmsgid, ...) {
   auto_diagnostic_group d;
   va_list ap;
   va_start(ap, gmsgid);
-  emit_diagnostic_valist( DK_SORRY, token_location, option_zero, gmsgid, &ap );
+  emit_diagnostic_valist( diagnostics::kind::sorry,
+			  token_location, option_zero, gmsgid, &ap );
   va_end(ap);
 }
 
@@ -2290,7 +2292,8 @@ cbl_unimplemented(const char *gmsgid, ...) {
   auto_diagnostic_group d;
   va_list ap;
   va_start(ap, gmsgid);
-  emit_diagnostic_valist( DK_SORRY, token_location, option_zero, gmsgid, &ap );
+  emit_diagnostic_valist( diagnostics::kind::sorry,
+			  token_location, option_zero, gmsgid, &ap );
   va_end(ap);
 }
 
@@ -2301,7 +2304,8 @@ cbl_unimplemented_at( const YYLTYPE& loc, const char *gmsgid, ... ) {
   auto_diagnostic_group d;
   va_list ap;
   va_start(ap, gmsgid);
-  emit_diagnostic_valist( DK_SORRY, token_location, option_zero, gmsgid, &ap );
+  emit_diagnostic_valist( diagnostics::kind::sorry,
+			  token_location, option_zero, gmsgid, &ap );
   va_end(ap);
 }
 
@@ -2318,7 +2322,8 @@ cbl_err(const char *fmt, ...) {
   verify_format(gmsgid);
   va_list ap;
   va_start(ap, fmt);
-  emit_diagnostic_valist( DK_FATAL, token_location, option_zero, gmsgid, &ap );
+  emit_diagnostic_valist( diagnostics::kind::fatal,
+			  token_location, option_zero, gmsgid, &ap );
   va_end(ap);
 }
 #pragma GCC diagnostic pop
@@ -2329,7 +2334,8 @@ cbl_errx(const char *gmsgid, ...) {
   auto_diagnostic_group d;
   va_list ap;
   va_start(ap, gmsgid);
-  emit_diagnostic_valist( DK_FATAL, token_location, option_zero, gmsgid, &ap );
+  emit_diagnostic_valist( diagnostics::kind::fatal,
+			  token_location, option_zero, gmsgid, &ap );
   va_end(ap);
   }
 
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index abbb97768f5e..bb6d6e28d592 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -19920,8 +19920,9 @@ aarch64_process_one_target_attr (char *arg_str)
 	      if (valid)
 		{
 		  set_option (&global_options, NULL, p_attr->opt_num, value,
-			      NULL, DK_UNSPECIFIED, input_location,
-			      global_dc);
+			      NULL,
+			      static_cast<int> (diagnostics::kind::unspecified),
+			      input_location, global_dc);
 		}
 	      else
 		{
diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc
index 09cb1337f94c..a41b52b1a6fd 100644
--- a/gcc/config/i386/i386-options.cc
+++ b/gcc/config/i386/i386-options.cc
@@ -1362,7 +1362,9 @@ ix86_valid_target_attribute_inner_p (tree fndecl, tree args, char *p_strings[],
 	  arg_ok = opt_enum_arg_to_value (opt, p + opt_len, &value, CL_TARGET);
 	  if (arg_ok)
 	    set_option (opts, enum_opts_set, opt, value,
-			p + opt_len, DK_UNSPECIFIED, input_location,
+			p + opt_len,
+			static_cast<int> (diagnostics::kind::unspecified),
+			input_location,
 			global_dc);
 	  else
 	    {
diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
index 38267202f668..b74affc8b5bc 100644
--- a/gcc/config/s390/s390.cc
+++ b/gcc/config/s390/s390.cc
@@ -16863,8 +16863,9 @@ s390_valid_target_attribute_inner_p (tree args,
 	      generate_option (opt, NULL, value, CL_TARGET, &decoded);
 	      s390_handle_option (opts, new_opts_set, &decoded, input_location);
 	      set_option (opts, new_opts_set, opt, value,
-			  p + opt_len, DK_UNSPECIFIED, input_location,
-			  global_dc);
+			  p + opt_len,
+			  static_cast<int> (diagnostics::kind::unspecified),
+			  input_location, global_dc);
 	    }
 	  else
 	    {
@@ -16881,8 +16882,9 @@ s390_valid_target_attribute_inner_p (tree args,
 	  arg_ok = opt_enum_arg_to_value (opt, p + opt_len, &value, CL_TARGET);
 	  if (arg_ok)
 	    set_option (opts, new_opts_set, opt, value,
-			p + opt_len, DK_UNSPECIFIED, input_location,
-			global_dc);
+			p + opt_len,
+			static_cast<int> (diagnostics::kind::unspecified),
+			input_location, global_dc);
 	  else
 	    {
 	      error ("attribute %<target%> argument %qs is unknown", orig_p);
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 2c3ef3dfc35d..c4cbf294a660 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -220,7 +220,8 @@ static void add_candidates (tree, tree, const vec<tree, va_gc> *, tree, tree,
 			    bool, tree, tree, int, struct z_candidate **,
 			    tsubst_flags_t);
 static conversion *merge_conversion_sequences (conversion *, conversion *);
-static tree build_temp (tree, tree, int, diagnostic_t *, tsubst_flags_t);
+static tree build_temp (tree, tree, int, enum diagnostics::kind *,
+			tsubst_flags_t);
 static conversion *build_identity_conv (tree, tree);
 static inline bool conv_binds_to_array_of_unknown_bound (conversion *);
 static bool conv_is_prvalue (conversion *);
@@ -6404,7 +6405,9 @@ build_conditional_expr (const op_location_t &loc,
 	       types when the enumeration is still being defined.  */;
 	  else if (complain & (cxx_dialect >= cxx26
 			       ? tf_warning_or_error : tf_warning))
-	    emit_diagnostic (cxx_dialect >= cxx26 ? DK_PEDWARN : DK_WARNING,
+	    emit_diagnostic ((cxx_dialect >= cxx26
+			      ? diagnostics::kind::pedwarn
+			      : diagnostics::kind::warning),
 			     loc, OPT_Wenum_compare, "enumerated mismatch "
 			     "in conditional expression: %qT vs %qT",
 			     arg2_type, arg3_type);
@@ -7585,8 +7588,9 @@ build_new_op (const op_location_t &loc, enum tree_code code, int flags,
 		      && (complain & tf_warning_or_error) == 0)
 		    result = error_mark_node;
 		  else if (cxx_dialect >= cxx26 || (complain & tf_warning))
-		    emit_diagnostic (cxx_dialect >= cxx26
-				     ? DK_PEDWARN : DK_WARNING,
+		    emit_diagnostic ((cxx_dialect >= cxx26
+				      ? diagnostics::kind::pedwarn
+				      : diagnostics::kind::warning),
 				     loc, OPT_Wenum_compare,
 				     "comparison between %q#T and %q#T",
 				     arg1_type, arg2_type);
@@ -8400,11 +8404,11 @@ complain_about_access (tree decl, tree diag_decl, tree diag_location,
 
 static tree
 build_temp (tree expr, tree type, int flags,
-	    diagnostic_t *diagnostic_kind, tsubst_flags_t complain)
+	    enum diagnostics::kind *diagnostic_kind, tsubst_flags_t complain)
 {
   int savew, savee;
 
-  *diagnostic_kind = DK_UNSPECIFIED;
+  *diagnostic_kind = diagnostics::kind::unspecified;
 
   /* If the source is a packed field, calling the copy constructor will require
      binding the field to the reference parameter to the copy constructor, and
@@ -8428,9 +8432,9 @@ build_temp (tree expr, tree type, int flags,
   expr = build_special_member_call (NULL_TREE, complete_ctor_identifier,
 				    &args, type, flags, complain);
   if (warningcount + werrorcount > savew)
-    *diagnostic_kind = DK_WARNING;
+    *diagnostic_kind = diagnostics::kind::warning;
   else if (errorcount > savee)
-    *diagnostic_kind = DK_ERROR;
+    *diagnostic_kind = diagnostics::kind::error;
   return expr;
 }
 
@@ -8642,7 +8646,7 @@ convert_like_internal (conversion *convs, tree expr, tree fn, int argnum,
 		       bool nested_p, tsubst_flags_t complain)
 {
   tree totype = convs->type;
-  diagnostic_t diag_kind;
+  enum diagnostics::kind diag_kind;
   int flags;
   location_t loc = cp_expr_loc_or_input_loc (expr);
 
@@ -9169,7 +9173,7 @@ convert_like_internal (conversion *convs, tree expr, tree fn, int argnum,
       if (convs->copy_init_p)
 	flags |= LOOKUP_ONLYCONVERTING;
       expr = build_temp (expr, totype, flags, &diag_kind, complain);
-      if (diag_kind && complain)
+      if (diag_kind != diagnostics::kind::unspecified && complain)
 	{
 	  auto_diagnostic_group d;
 	  maybe_print_user_conv_context (convs);
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 0ee0d968fac5..754e85f7fac4 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -161,13 +161,16 @@ constexpr_error (location_t location, bool constexpr_fundef_p,
   if (!constexpr_fundef_p)
     {
       /* Report an error that cannot be suppressed.  */
-      diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_ERROR);
+      diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
+			   diagnostics::kind::error);
       ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
     }
   else if (warn_invalid_constexpr)
     {
       diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
-			   cxx_dialect < cxx23 ? DK_PEDWARN : DK_WARNING);
+			   (cxx_dialect < cxx23
+			    ? diagnostics::kind::pedwarn
+			    : diagnostics::kind::warning));
       diagnostic.m_option_id = OPT_Winvalid_constexpr;
       ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
     }
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index bcdcec769353..9534e673a738 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -8569,7 +8569,7 @@ extern void maybe_warn_pessimizing_move	     (tree, tree, bool);
 /* in typeck2.cc */
 extern void require_complete_eh_spec_types	(tree, tree);
 extern bool cxx_incomplete_type_diagnostic	(location_t, const_tree,
-						 const_tree, diagnostic_t);
+						 const_tree, enum diagnostics::kind);
 inline location_t
 loc_or_input_loc (location_t loc)
 {
@@ -8617,7 +8617,7 @@ cp_expr_loc_or_input_loc (const_tree t)
 
 inline bool
 cxx_incomplete_type_diagnostic (const_tree value, const_tree type,
-				diagnostic_t diag_kind)
+				enum diagnostics::kind diag_kind)
 {
   return cxx_incomplete_type_diagnostic (cp_expr_loc_or_input_loc (value),
 					 value, type, diag_kind);
@@ -8628,7 +8628,7 @@ extern void cxx_incomplete_type_error		(location_t, const_tree,
 inline void
 cxx_incomplete_type_error (const_tree value, const_tree type)
 {
-  cxx_incomplete_type_diagnostic (value, type, DK_ERROR);
+  cxx_incomplete_type_diagnostic (value, type, diagnostics::kind::error);
 }
 
 extern void cxx_incomplete_type_inform 	        (const_tree);
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 15497552fde0..3f76dd11192d 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -110,7 +110,7 @@ static void initialize_local_var (tree, tree, bool);
 static void expand_static_init (tree, tree);
 static location_t smallest_type_location (const cp_decl_specifier_seq*);
 static bool identify_goto (tree, location_t, const location_t *,
-			   diagnostic_t, bool);
+			   enum diagnostics::kind, bool);
 
 /* The following symbols are subsumed in the cp_global_trees array, and
    listed here individually for documentation purposes.
@@ -3740,10 +3740,10 @@ decl_jump_unsafe (tree decl)
 
 static bool
 identify_goto (tree decl, location_t loc, const location_t *locus,
-	       diagnostic_t diag_kind, bool computed)
+	       enum diagnostics::kind diag_kind, bool computed)
 {
   if (computed)
-    diag_kind = DK_WARNING;
+    diag_kind = diagnostics::kind::warning;
   bool complained
     = emit_diagnostic (diag_kind, loc, 0,
 		       decl ? G_("jump to label %qD")
@@ -3779,7 +3779,8 @@ check_previous_goto_1 (tree decl, cp_binding_level* level, tree names,
 
   if (exited_omp)
     {
-      complained = identify_goto (decl, input_location, locus, DK_ERROR,
+      complained = identify_goto (decl, input_location, locus,
+				  diagnostics::kind::error,
 				  computed);
       if (complained)
 	inform (input_location, "  exits OpenMP structured block");
@@ -3801,7 +3802,8 @@ check_previous_goto_1 (tree decl, cp_binding_level* level, tree names,
 
 	  if (!identified)
 	    {
-	      complained = identify_goto (decl, input_location, locus, DK_ERROR,
+	      complained = identify_goto (decl, input_location, locus,
+					  diagnostics::kind::error,
 					  computed);
 	      identified = 2;
 	    }
@@ -3869,7 +3871,8 @@ check_previous_goto_1 (tree decl, cp_binding_level* level, tree names,
       if (inf)
 	{
 	  if (identified < 2)
-	    complained = identify_goto (decl, input_location, locus, DK_ERROR,
+	    complained = identify_goto (decl, input_location, locus,
+					diagnostics::kind::error,
 					computed);
 	  identified = 2;
 	  if (complained)
@@ -3880,7 +3883,8 @@ check_previous_goto_1 (tree decl, cp_binding_level* level, tree names,
   if (!vec_safe_is_empty (computed))
     {
       if (!identified)
-	complained = identify_goto (decl, input_location, locus, DK_ERROR,
+	complained = identify_goto (decl, input_location, locus,
+				    diagnostics::kind::error,
 				    computed);
       identified = 2;
       if (complained)
@@ -3952,14 +3956,14 @@ check_goto_1 (named_label_entry *ent, bool computed)
       || ent->in_omp_scope || ent->in_stmt_expr
       || !vec_safe_is_empty (ent->bad_decls))
     {
-      diagnostic_t diag_kind = DK_PERMERROR;
+      enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
       if (ent->in_try_scope || ent->in_catch_scope || ent->in_constexpr_if
 	  || ent->in_consteval_if || ent->in_transaction_scope
 	  || ent->in_omp_scope || ent->in_stmt_expr)
-	diag_kind = DK_ERROR;
+	diag_kind = diagnostics::kind::error;
       complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
 				  &input_location, diag_kind, computed);
-      identified = 1 + (diag_kind == DK_ERROR);
+      identified = 1 + (diag_kind == diagnostics::kind::error);
     }
 
   FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, ix, bad)
@@ -3972,7 +3976,9 @@ check_goto_1 (named_label_entry *ent, bool computed)
 	  if (identified == 1)
 	    {
 	      complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
-					  &input_location, DK_ERROR, computed);
+					  &input_location,
+					  diagnostics::kind::error,
+					  computed);
 	      identified = 2;
 	    }
 	  if (complained)
@@ -4016,7 +4022,8 @@ check_goto_1 (named_label_entry *ent, bool computed)
 	      {
 		complained = identify_goto (decl,
 					    DECL_SOURCE_LOCATION (decl),
-					    &input_location, DK_ERROR,
+					    &input_location,
+					    diagnostics::kind::error,
 					    computed);
 		identified = 2;
 	      }
@@ -4040,7 +4047,8 @@ check_goto_1 (named_label_entry *ent, bool computed)
 		{
 		  complained
 		    = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
-				     &input_location, DK_ERROR, computed);
+				     &input_location, diagnostics::kind::error,
+				     computed);
 		  identified = 2;
 		}
 	      if (complained)
@@ -4056,7 +4064,8 @@ check_goto_1 (named_label_entry *ent, bool computed)
 		    {
 		      complained
 			= identify_goto (decl, DECL_SOURCE_LOCATION (decl),
-					 &input_location, DK_ERROR, computed);
+					 &input_location, diagnostics::kind::error,
+					 computed);
 		      identified = 2;
 		    }
 		  if (complained)
@@ -11260,12 +11269,12 @@ grokfndecl (tree ctype,
 	   t && t != void_list_node; t = TREE_CHAIN (t))
 	if (TREE_PURPOSE (t))
 	  {
-	    diagnostic_t diag_kind = DK_PERMERROR;
+	    enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
 	    /* For templates, mark the default argument as erroneous and give a
 	       hard error.  */
 	    if (processing_template_decl)
 	      {
-		diag_kind = DK_ERROR;
+		diag_kind = diagnostics::kind::error;
 		TREE_PURPOSE (t) = error_mark_node;
 	      }
 	    if (!has_errored)
@@ -17379,7 +17388,8 @@ xref_basetypes (tree ref, tree base_list)
 	 compatibility.  */
       if (processing_template_decl
 	  && CLASS_TYPE_P (basetype) && TYPE_BEING_DEFINED (basetype))
-	cxx_incomplete_type_diagnostic (NULL_TREE, basetype, DK_PEDWARN);
+	cxx_incomplete_type_diagnostic (NULL_TREE, basetype,
+					diagnostics::kind::pedwarn);
       if (!dependent_type_p (basetype)
 	  && !complete_type_or_else (basetype, NULL))
 	/* An incomplete type.  Remove it from the list.  */
diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc
index f6d81e507761..56d7392a1200 100644
--- a/gcc/cp/error.cc
+++ b/gcc/cp/error.cc
@@ -253,13 +253,13 @@ static void
 cp_adjust_diagnostic_info (diagnostics::context *context,
 			   diagnostic_info *diagnostic)
 {
-  if (diagnostic->m_kind == DK_ERROR)
+  if (diagnostic->m_kind == diagnostics::kind::error)
     if (tree tmpl = get_current_template ())
       {
 	diagnostic->m_option_id = OPT_Wtemplate_body;
 
 	if (context->m_permissive)
-	  diagnostic->m_kind = DK_WARNING;
+	  diagnostic->m_kind = diagnostics::kind::warning;
 
 	bool existed;
 	location_t &error_loc
@@ -4015,7 +4015,7 @@ public:
 	    diagnostic_show_locus (&m_text_output.get_context (),
 				   m_text_output.get_source_printing_options (),
 				   &rich_loc,
-				   DK_NOTE, pp);
+				   diagnostics::kind::note, pp);
 	    pp_set_prefix (pp, saved_prefix);
 	  }
       }
@@ -4027,7 +4027,7 @@ public:
 	diagnostic_show_locus (&m_text_output.get_context (),
 			       m_text_output.get_source_printing_options (),
 			       &rich_loc,
-			       DK_NOTE, pp);
+			       diagnostics::kind::note, pp);
 	pp_set_prefix (pp, saved_prefix);
       }
   }
@@ -4924,7 +4924,9 @@ pedwarn_cxx98 (location_t location,
 
   va_start (ap, gmsgid);
   diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
-		       (cxx_dialect == cxx98) ? DK_PEDWARN : DK_WARNING);
+		       (cxx_dialect == cxx98
+			? diagnostics::kind::pedwarn
+			: diagnostics::kind::warning));
   diagnostic.m_option_id = option_id;
   ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
   va_end (ap);
diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index 0a389fb6ecde..09fb4f365522 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -4181,7 +4181,8 @@ build_vec_delete_1 (location_t loc, tree base, tree maxindex, tree type,
 			  "possible problem detected in invocation of "
 			  "operator %<delete []%>"))
 	    {
-	      cxx_incomplete_type_diagnostic (base, type, DK_WARNING);
+	      cxx_incomplete_type_diagnostic (base, type,
+					      diagnostics::kind::warning);
 	      inform (loc, "neither the destructor nor the "
 		      "class-specific operator %<delete []%> will be called, "
 		      "even if they are declared when the class is defined");
@@ -5286,7 +5287,8 @@ build_delete (location_t loc, tree otype, tree addr,
 				  "possible problem detected in invocation of "
 				  "%<operator delete%>"))
 		    {
-		      cxx_incomplete_type_diagnostic (addr, type, DK_WARNING);
+		      cxx_incomplete_type_diagnostic (addr, type,
+						      diagnostics::kind::warning);
 		      inform (loc,
 			      "neither the destructor nor the class-specific "
 			      "%<operator delete%> will be called, even if "
diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc
index a4089c53c67b..00b79f07e6a0 100644
--- a/gcc/cp/method.cc
+++ b/gcc/cp/method.cc
@@ -1187,15 +1187,15 @@ early_check_defaulted_comparison (tree fn)
   if (!DECL_OVERLOADED_OPERATOR_IS (fn, SPACESHIP_EXPR)
       && !same_type_p (TREE_TYPE (TREE_TYPE (fn)), boolean_type_node))
     {
-      diagnostic_t kind = DK_UNSPECIFIED;
+      enum diagnostics::kind kind = diagnostics::kind::unspecified;
       int opt = 0;
       if (is_auto (TREE_TYPE (fn)))
-	kind = DK_PEDWARN;
+	kind = diagnostics::kind::pedwarn;
       else
-	kind = DK_ERROR;
+	kind = diagnostics::kind::error;
       emit_diagnostic (kind, loc, opt,
 		       "defaulted %qD must return %<bool%>", fn);
-      if (kind == DK_ERROR)
+      if (kind == diagnostics::kind::error)
 	ok = false;
     }
 
@@ -3586,21 +3586,24 @@ maybe_delete_defaulted_fn (tree fn, tree implicit_fn)
 	      the program is ill-formed"  */
 	   || !TYPE_REF_P (parmtype)));
   /* Decide if we want to emit a pedwarn, error, or a warning.  */
-  diagnostic_t diag_kind;
+  enum diagnostics::kind diag_kind;
   int opt;
   if (illformed_p)
     {
-      diag_kind = DK_ERROR;
+      diag_kind = diagnostics::kind::error;
       opt = 0;
     }
   else
     {
-      diag_kind = cxx_dialect >= cxx20 ? DK_WARNING : DK_PEDWARN;
+      diag_kind = (cxx_dialect >= cxx20
+		   ? diagnostics::kind::warning
+		   : diagnostics::kind::pedwarn);
       opt = OPT_Wdefaulted_function_deleted;
     }
 
   /* Don't warn for template instantiations.  */
-  if (DECL_TEMPLATE_INSTANTIATION (fn) && diag_kind == DK_WARNING)
+  if (DECL_TEMPLATE_INSTANTIATION (fn)
+      && diag_kind == diagnostics::kind::warning)
     return;
 
   const char *wmsg;
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 077083550a7e..acad66571448 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -18318,22 +18318,23 @@ module_state::write_ordinary_maps (elf_out *to, range_t &info,
 /* Return the prefix to use for dumping a #pragma diagnostic change to DK.  */
 
 static const char *
-dk_string (diagnostic_t dk)
+dk_string (enum diagnostics::kind dk)
 {
-  gcc_assert (dk > DK_UNSPECIFIED && dk < DK_LAST_DIAGNOSTIC_KIND);
-  if (dk == DK_IGNORED)
-    /* diagnostic.def has an empty string for ignored.  */
+  gcc_assert (dk > diagnostics::kind::unspecified
+	      && dk < diagnostics::kind::last_diagnostic_kind);
+  if (dk == diagnostics::kind::ignored)
+    /* diagnostics/kinds.def has an empty string for ignored.  */
     return "ignored: ";
   else
-    return get_diagnostic_kind_text (dk);
+    return diagnostics::get_text_for_kind (dk);
 }
 
 /* Dump one #pragma GCC diagnostic entry.  */
 
 static bool
-dump_dc_change (unsigned index, unsigned opt, diagnostic_t dk)
+dump_dc_change (unsigned index, unsigned opt, enum diagnostics::kind dk)
 {
-  if (dk == DK_POP)
+  if (dk == diagnostics::kind::pop)
     return dump (" Index %u: pop from %d", index, opt);
   else
     return dump (" Index %u: %s%s", index, dk_string (dk),
@@ -18360,9 +18361,10 @@ module_state::write_diagnostic_classification (elf_out *to,
   unsigned len = changes.length ();
 
   /* We don't want to write out any entries that came from one of our imports.
-     But then we need to adjust the total, and change DK_POP targets to match
-     the index in our actual output.  So remember how many lines we had skipped
-     at each step, where -1 means this line itself is skipped.  */
+     But then we need to adjust the total, and change diagnostics::kind::pop
+     targets to match the index in our actual output.  So remember how many
+     lines we had skipped at each step, where -1 means this line itself
+     is skipped.  */
   int skips = 0;
   auto_vec<int> skips_at (len);
   skips_at.safe_grow (len);
@@ -18395,10 +18397,10 @@ module_state::write_diagnostic_classification (elf_out *to,
       if (sec.streaming_p ())
 	{
 	  unsigned opt = c.option;
-	  if (c.kind == DK_POP)
+	  if (c.kind == diagnostics::kind::pop)
 	    opt -= skips_at[opt];
 	  sec.u (opt);
-	  sec.u (c.kind);
+	  sec.u (static_cast<unsigned> (c.kind));
 	  dump () && dump_dc_change (i - skips_at[i], opt, c.kind);
 	}
     }
@@ -18433,8 +18435,8 @@ module_state::read_diagnostic_classification (diagnostics::context *dc)
     {
       location_t loc = read_location (sec);
       int opt = sec.u ();
-      diagnostic_t kind = (diagnostic_t) sec.u ();
-      if (kind == DK_POP)
+      enum diagnostics::kind kind = (enum diagnostics::kind) sec.u ();
+      if (kind == diagnostics::kind::pop)
 	/* For a pop, opt is the 'changes' index to return to.  */
 	opt += offset;
       changes.quick_push ({ loc, opt, kind });
@@ -18449,7 +18451,7 @@ module_state::read_diagnostic_classification (diagnostics::context *dc)
 	gcc_checking_assert (i >= offset);
 
 	const auto &c = changes[i];
-	if (c.kind != DK_POP)
+	if (c.kind != diagnostics::kind::pop)
 	  break;
 	else if (c.option == offset)
 	  {
@@ -18466,7 +18468,7 @@ module_state::read_diagnostic_classification (diagnostics::context *dc)
       /* It didn't, so add a pop at its last location to avoid affecting later
 	 imports.  */
       location_t last_loc = ordinary_locs.first + ordinary_locs.second - 1;
-      changes.quick_push ({ last_loc, offset, DK_POP });
+      changes.quick_push ({ last_loc, offset, diagnostics::kind::pop });
       dump () && dump (" Adding final pop from index %d", offset);
     }
 
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index b1626acb50b7..ef68db40fdf0 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -5266,7 +5266,7 @@ cp_parser_userdef_numeric_literal (cp_parser *parser)
 	      && (id_equal (suffix_id, "i")
 		  || id_equal (suffix_id, "if")
 		  || id_equal (suffix_id, "il")));
-  diagnostic_t kind = DK_ERROR;
+  enum diagnostics::kind kind = diagnostics::kind::error;
   int opt = 0;
 
   if (i14 && ext)
@@ -5276,7 +5276,7 @@ cp_parser_userdef_numeric_literal (cp_parser *parser)
       if (cxlit == error_mark_node)
 	{
 	  /* No <complex>, so pedwarn and use GNU semantics.  */
-	  kind = DK_PEDWARN;
+	  kind = diagnostics::kind::pedwarn;
 	  opt = OPT_Wpedantic;
 	}
     }
@@ -5303,7 +5303,7 @@ cp_parser_userdef_numeric_literal (cp_parser *parser)
 	      "to enable more built-in suffixes");
   }
 
-  if (kind == DK_ERROR)
+  if (kind == diagnostics::kind::error)
     value = error_mark_node;
   else
     {
@@ -6644,7 +6644,8 @@ cp_parser_primary_expression (cp_parser *parser,
    member template.  */
 
 static void
-missing_template_diag (location_t loc, diagnostic_t diag_kind = DK_WARNING)
+missing_template_diag (location_t loc,
+		       enum diagnostics::kind diag_kind = diagnostics::kind::warning)
 {
   if (warning_suppressed_at (loc, OPT_Wmissing_template_keyword))
     return;
@@ -8842,8 +8843,10 @@ cp_parser_dot_deref_incomplete (tree *scope, cp_expr *postfix_expression,
 {
   /* In a template, be permissive by treating an object expression
      of incomplete type as dependent (after a pedwarn).  */
-  diagnostic_t kind = (processing_template_decl
-		       && MAYBE_CLASS_TYPE_P (*scope) ? DK_PEDWARN : DK_ERROR);
+  enum diagnostics::kind kind = ((processing_template_decl
+				  && MAYBE_CLASS_TYPE_P (*scope))
+				 ? diagnostics::kind::pedwarn
+				 : diagnostics::kind::error);
 
   switch (TREE_CODE (*postfix_expression))
     {
@@ -8855,27 +8858,27 @@ cp_parser_dot_deref_incomplete (tree *scope, cp_expr *postfix_expression,
     case IMPLICIT_CONV_EXPR:
     case VIEW_CONVERT_EXPR:
     case NON_LVALUE_EXPR:
-      kind = DK_ERROR;
+      kind = diagnostics::kind::error;
       break;
     case OVERLOAD:
       /* Don't emit any diagnostic for OVERLOADs.  */
-      kind = DK_IGNORED;
+      kind = diagnostics::kind::ignored;
       break;
     default:
       /* Avoid clobbering e.g. DECLs.  */
       if (!EXPR_P (*postfix_expression))
-	kind = DK_ERROR;
+	kind = diagnostics::kind::error;
       break;
     }
 
-  if (kind == DK_IGNORED)
+  if (kind == diagnostics::kind::ignored)
     return false;
 
   location_t exploc = location_of (*postfix_expression);
   cxx_incomplete_type_diagnostic (exploc, *postfix_expression, *scope, kind);
   if (!MAYBE_CLASS_TYPE_P (*scope))
     return true;
-  if (kind == DK_ERROR)
+  if (kind == diagnostics::kind::error)
     *scope = *postfix_expression = error_mark_node;
   else if (processing_template_decl)
     {
@@ -9498,7 +9501,7 @@ cp_parser_unary_expression (cp_parser *parser, cp_id_kind * pidk,
 	    diagnostic_push_diagnostics (global_dc, input_location);
 	    diagnostic_classify_diagnostic
 	      (global_dc, OPT_Wconditionally_supported,
-	       DK_IGNORED, input_location);
+	       diagnostics::kind::ignored, input_location);
 	    /* Parse the cast-expression.  */
 	    expr = cp_parser_simple_cast_expression (parser);
 	    /* Restore the PEDANTIC flag.  */
@@ -33558,7 +33561,9 @@ cp_parser_constructor_declarator_p (cp_parser *parser, cp_parser_flags flags,
       && cp_lexer_peek_token (parser->lexer)->type == CPP_TEMPLATE_ID)
     {
       auto_diagnostic_group d;
-      if (emit_diagnostic (cxx_dialect >= cxx20 ? DK_PEDWARN : DK_WARNING,
+      if (emit_diagnostic ((cxx_dialect >= cxx20
+			    ? diagnostics::kind::pedwarn
+			    : diagnostics::kind::warning),
 			   input_location, OPT_Wtemplate_id_cdtor,
 			   "template-id not allowed for constructor in C++20"))
 	inform (input_location, "remove the %qs", "< >");
@@ -52898,11 +52903,14 @@ cp_parser_omp_error (cp_parser *parser, cp_token *pragma_tok,
       if (msg == NULL)
 	msg = _("<message unknown at compile time>");
     }
+  const enum diagnostics::kind diag_kind = (severity_fatal
+					    ? diagnostics::kind::error
+					    : diagnostics::kind::warning);
   if (msg)
-    emit_diagnostic (severity_fatal ? DK_ERROR : DK_WARNING, loc, 0,
+    emit_diagnostic (diag_kind, loc, 0,
 		     "%<pragma omp error%> encountered: %s", msg);
   else
-    emit_diagnostic (severity_fatal ? DK_ERROR : DK_WARNING, loc, 0,
+    emit_diagnostic (diag_kind, loc, 0,
 		     "%<pragma omp error%> encountered");
   return false;
 }
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 3362a6f8f9ca..e00f235732d1 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -31627,7 +31627,9 @@ do_class_deduction (tree ptype, tree tmpl, tree init, tree outer_targs,
 	  /* Be permissive with equivalent alias templates.  */
 	  tree u = get_underlying_template (tmpl);
 	  auto_diagnostic_group d;
-	  diagnostic_t dk = (u == tmpl) ? DK_ERROR : DK_PEDWARN;
+	  const enum diagnostics::kind dk = ((u == tmpl)
+					     ? diagnostics::kind::error
+					     : diagnostics::kind::pedwarn);
 	  bool complained
 	    = emit_diagnostic (dk, input_location, 0,
 			       "alias template deduction only available "
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 28baf7b3172b..68afc82e4b7e 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -13653,7 +13653,8 @@ check_trait_type (tree type, int kind = 1)
 
   type = complete_type (strip_array_types (type));
   if (!COMPLETE_TYPE_P (type)
-      && cxx_incomplete_type_diagnostic (NULL_TREE, type, DK_PERMERROR)
+      && cxx_incomplete_type_diagnostic (NULL_TREE, type,
+					 diagnostics::kind::permerror)
       && !flag_permissive)
     return false;
   return true;
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index 447fe810633d..7242749b19f9 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -155,7 +155,7 @@ complete_type_or_maybe_complain (tree type, tree value, tsubst_flags_t complain)
   else if (!COMPLETE_TYPE_P (type))
     {
       if (complain & tf_error)
-	cxx_incomplete_type_diagnostic (value, type, DK_ERROR);
+	cxx_incomplete_type_diagnostic (value, type, diagnostics::kind::error);
       note_failed_type_completion (type, complain);
       return NULL_TREE;
     }
@@ -618,7 +618,7 @@ type_after_usual_arithmetic_conversions (tree t1, tree t2)
 
 static void
 composite_pointer_error (const op_location_t &location,
-			 diagnostic_t kind, tree t1, tree t2,
+			 enum diagnostics::kind kind, tree t1, tree t2,
 			 composite_pointer_operation operation)
 {
   switch (operation)
@@ -690,7 +690,7 @@ composite_pointer_type_r (const op_location_t &location,
   else
     {
       if (complain & tf_error)
-	composite_pointer_error (location, DK_PERMERROR,
+	composite_pointer_error (location, diagnostics::kind::permerror,
 				 t1, t2, operation);
       else
 	return error_mark_node;
@@ -716,7 +716,7 @@ composite_pointer_type_r (const op_location_t &location,
 			TYPE_PTRMEM_CLASS_TYPE (t2)))
 	{
 	  if (complain & tf_error)
-	    composite_pointer_error (location, DK_PERMERROR,
+	    composite_pointer_error (location, diagnostics::kind::permerror,
 				     t1, t2, operation);
 	  else
 	    return error_mark_node;
@@ -851,7 +851,8 @@ composite_pointer_type (const op_location_t &location,
       else
         {
           if (complain & tf_error)
-	    composite_pointer_error (location, DK_ERROR, t1, t2, operation);
+	    composite_pointer_error (location, diagnostics::kind::error,
+				     t1, t2, operation);
           return error_mark_node;
         }
     }
@@ -10779,7 +10780,9 @@ maybe_warn_about_returning_address_of_local (tree retval, location_t loc)
     {
       if (TYPE_REF_P (valtype))
 	/* P2748 made this an error in C++26.  */
-	emit_diagnostic (cxx_dialect >= cxx26 ? DK_PERMERROR : DK_WARNING,
+	emit_diagnostic ((cxx_dialect >= cxx26
+			  ? diagnostics::kind::permerror
+			  : diagnostics::kind::warning),
 			 loc, OPT_Wreturn_local_addr,
 			 "returning reference to temporary");
       else if (TYPE_PTR_P (valtype))
diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc
index 45edd1801739..ccf8ffe4f63e 100644
--- a/gcc/cp/typeck2.cc
+++ b/gcc/cp/typeck2.cc
@@ -290,11 +290,12 @@ cxx_incomplete_type_inform (const_tree type)
 /* Print an error message for invalid use of an incomplete type.
    VALUE is the expression that was used (or 0 if that isn't known)
    and TYPE is the type that was invalid.  DIAG_KIND indicates the
-   type of diagnostic (see diagnostic.def).  */
+   type of diagnostic (see diagnostics/kinds.def).  */
 
 bool
 cxx_incomplete_type_diagnostic (location_t loc, const_tree value,
-				const_tree type, diagnostic_t diag_kind)
+				const_tree type,
+				enum diagnostics::kind diag_kind)
 {
   bool is_decl = false, complained = false;
 
@@ -440,7 +441,7 @@ cxx_incomplete_type_diagnostic (location_t loc, const_tree value,
 void
 cxx_incomplete_type_error (location_t loc, const_tree value, const_tree type)
 {
-  cxx_incomplete_type_diagnostic (loc, value, type, DK_ERROR);
+  cxx_incomplete_type_diagnostic (loc, value, type, diagnostics::kind::error);
 }
 
 
@@ -2627,7 +2628,7 @@ add_exception_specifier (tree list, tree spec, tsubst_flags_t complain)
   bool ok;
   tree core = spec;
   bool is_ptr;
-  diagnostic_t diag_type = DK_UNSPECIFIED; /* none */
+  enum diagnostics::kind diag_type = diagnostics::kind::unspecified; /* none */
 
   if (spec == error_mark_node)
     return list;
@@ -2659,7 +2660,7 @@ add_exception_specifier (tree list, tree spec, tsubst_flags_t complain)
 	 and calls.  So just give a pedwarn at this point; we will give an
 	 error later if we hit one of those two cases.  */
       if (!COMPLETE_TYPE_P (complete_type (core)))
-	diag_type = DK_PEDWARN; /* pedwarn */
+	diag_type = diagnostics::kind::pedwarn; /* pedwarn */
     }
 
   if (ok)
@@ -2673,9 +2674,9 @@ add_exception_specifier (tree list, tree spec, tsubst_flags_t complain)
 	list = tree_cons (NULL_TREE, spec, list);
     }
   else
-    diag_type = DK_ERROR; /* error */
+    diag_type = diagnostics::kind::error; /* error */
 
-  if (diag_type != DK_UNSPECIFIED
+  if (diag_type != diagnostics::kind::unspecified
       && (complain & tf_warning_or_error))
     cxx_incomplete_type_diagnostic (NULL_TREE, core, diag_type);
 
diff --git a/gcc/d/d-diagnostic.cc b/gcc/d/d-diagnostic.cc
index f7e380b1119a..44749344ce48 100644
--- a/gcc/d/d-diagnostic.cc
+++ b/gcc/d/d-diagnostic.cc
@@ -185,7 +185,7 @@ escape_d_format (const char *format)
 static void ATTRIBUTE_GCC_DIAG(3,0)
 d_diagnostic_report_diagnostic (const SourceLoc &loc, int opt,
 				const char *format, va_list ap,
-				diagnostic_t kind, bool verbatim)
+				enum diagnostics::kind kind, bool verbatim)
 {
   va_list argp;
   va_copy (argp, ap);
@@ -224,7 +224,7 @@ void D_ATTRIBUTE_FORMAT(2,0) ATTRIBUTE_GCC_DIAG(2,0)
 verrorReport (const SourceLoc loc, const char *format, va_list ap,
 	      ErrorKind kind, const char *prefix1, const char *prefix2)
 {
-  diagnostic_t diag_kind = DK_UNSPECIFIED;
+  enum diagnostics::kind diag_kind = diagnostics::kind::unspecified;
   int opt = 0;
   bool verbatim = false;
   char *xformat;
@@ -238,7 +238,9 @@ verrorReport (const SourceLoc loc, const char *format, va_list ap,
       if (global.gag && !global.params.v.showGaggedErrors)
 	return;
 
-      diag_kind = global.gag ? DK_ANACHRONISM : DK_ERROR;
+      diag_kind = (global.gag
+		   ? diagnostics::kind::anachronism
+		   : diagnostics::kind::error);
     }
   else if (kind == ErrorKind::warning)
     {
@@ -254,7 +256,7 @@ verrorReport (const SourceLoc loc, const char *format, va_list ap,
       if (global.params.useWarnings == DIAGNOSTICerror)
 	global.warnings++;
 
-      diag_kind = DK_WARNING;
+      diag_kind = diagnostics::kind::warning;
     }
   else if (kind == ErrorKind::deprecation)
     {
@@ -270,11 +272,11 @@ verrorReport (const SourceLoc loc, const char *format, va_list ap,
 	}
 
       opt = OPT_Wdeprecated;
-      diag_kind = DK_WARNING;
+      diag_kind = diagnostics::kind::warning;
     }
   else if (kind == ErrorKind::message)
     {
-      diag_kind = DK_NOTE;
+      diag_kind = diagnostics::kind::note;
       verbatim = true;
     }
   else if (kind == ErrorKind::tip)
@@ -282,7 +284,7 @@ verrorReport (const SourceLoc loc, const char *format, va_list ap,
       if (global.gag)
 	return;
 
-      diag_kind = DK_DEBUG;
+      diag_kind = diagnostics::kind::debug;
       verbatim = true;
     }
   else
@@ -328,7 +330,8 @@ verrorReportSupplemental (const SourceLoc loc, const char* format, va_list ap,
   else
     gcc_unreachable ();
 
-  d_diagnostic_report_diagnostic (loc, 0, format, ap, DK_NOTE, false);
+  d_diagnostic_report_diagnostic (loc, 0, format, ap, diagnostics::kind::note,
+				  false);
 }
 
 /* Call this after printing out fatal error messages to clean up and
diff --git a/gcc/diagnostic-core.h b/gcc/diagnostic-core.h
index 64377279b356..fc32f4816225 100644
--- a/gcc/diagnostic-core.h
+++ b/gcc/diagnostic-core.h
@@ -23,23 +23,9 @@ along with GCC; see the file COPYING3.  If not see
 #define GCC_DIAGNOSTIC_CORE_H
 
 #include "bversion.h"
+#include "diagnostics/kinds.h"
 #include "diagnostics/option-id.h"
 
-/* Constants used to discriminate diagnostics.  */
-typedef enum
-{
-#define DEFINE_DIAGNOSTIC_KIND(K, msgid, C) K,
-#include "diagnostic.def"
-#undef DEFINE_DIAGNOSTIC_KIND
-  DK_LAST_DIAGNOSTIC_KIND,
-  /* This is used for tagging pragma pops in the diagnostic
-     classification history chain.  */
-  DK_POP,
-  /* This is used internally to note that a diagnostic is enabled
-     without mandating any specific type.  */
-  DK_ANY,
-} diagnostic_t;
-
 /* RAII-style class for grouping related diagnostics within global_dc.  */
 
 class auto_diagnostic_group
@@ -156,20 +142,20 @@ extern void inform_n (location_t, unsigned HOST_WIDE_INT, const char *,
 		      const char *, ...)
     ATTRIBUTE_GCC_DIAG(3,5) ATTRIBUTE_GCC_DIAG(4,5);
 extern void verbatim (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
-extern bool emit_diagnostic (diagnostic_t,
+extern bool emit_diagnostic (enum diagnostics::kind,
 			     location_t,
 			     diagnostics::option_id,
 			     const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
-extern bool emit_diagnostic (diagnostic_t,
+extern bool emit_diagnostic (enum diagnostics::kind,
 			     rich_location *,
 			     diagnostics::option_id,
 			     const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
-extern bool emit_diagnostic_valist (diagnostic_t,
+extern bool emit_diagnostic_valist (enum diagnostics::kind,
 				    location_t,
 				    diagnostics::option_id,
 				    const char *, va_list *)
   ATTRIBUTE_GCC_DIAG (4,0);
-extern bool emit_diagnostic_valist_meta (diagnostic_t,
+extern bool emit_diagnostic_valist_meta (enum diagnostics::kind,
 					 rich_location *,
 					 const diagnostics::metadata *,
 					 diagnostics::option_id,
diff --git a/gcc/diagnostic-global-context.cc b/gcc/diagnostic-global-context.cc
index c53af2e8c1f6..500f19cfb4f9 100644
--- a/gcc/diagnostic-global-context.cc
+++ b/gcc/diagnostic-global-context.cc
@@ -53,7 +53,7 @@ verbatim (const char *gmsgid, ...)
    implying global_dc and taking a variable argument list.  */
 
 bool
-emit_diagnostic (diagnostic_t kind,
+emit_diagnostic (enum diagnostics::kind kind,
 		 location_t location,
 		 diagnostics::option_id option_id,
 		 const char *gmsgid, ...)
@@ -71,7 +71,7 @@ emit_diagnostic (diagnostic_t kind,
 /* As above, but for rich_location *.  */
 
 bool
-emit_diagnostic (diagnostic_t kind,
+emit_diagnostic (enum diagnostics::kind kind,
 		 rich_location *richloc,
 		 diagnostics::option_id option_id,
 		 const char *gmsgid, ...)
@@ -88,7 +88,7 @@ emit_diagnostic (diagnostic_t kind,
 /* As above, but taking a variable argument list.  */
 
 bool
-emit_diagnostic_valist (diagnostic_t kind,
+emit_diagnostic_valist (enum diagnostics::kind kind,
 			location_t location,
 			diagnostics::option_id option_id,
 			const char *gmsgid, va_list *ap)
@@ -101,7 +101,7 @@ emit_diagnostic_valist (diagnostic_t kind,
 /* As above, but with rich_location and metadata.  */
 
 bool
-emit_diagnostic_valist_meta (diagnostic_t kind,
+emit_diagnostic_valist_meta (enum diagnostics::kind kind,
 			     rich_location *richloc,
 			     const diagnostics::metadata *metadata,
 			     diagnostics::option_id option_id,
@@ -120,7 +120,8 @@ inform (location_t location, const char *gmsgid, ...)
   va_list ap;
   va_start (ap, gmsgid);
   rich_location richloc (line_table, location);
-  global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap, DK_NOTE);
+  global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
+			      diagnostics::kind::note);
   va_end (ap);
 }
 
@@ -133,7 +134,8 @@ inform (rich_location *richloc, const char *gmsgid, ...)
   auto_diagnostic_group d;
   va_list ap;
   va_start (ap, gmsgid);
-  global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap, DK_NOTE);
+  global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap,
+			      diagnostics::kind::note);
   va_end (ap);
 }
 
@@ -149,7 +151,7 @@ inform_n (location_t location, unsigned HOST_WIDE_INT n,
   rich_location richloc (line_table, location);
   global_dc->diagnostic_n_impl (&richloc, nullptr, -1, n,
 				singular_gmsgid, plural_gmsgid,
-				&ap, DK_NOTE);
+				&ap, diagnostics::kind::note);
   va_end (ap);
 }
 
@@ -164,7 +166,8 @@ warning (diagnostics::option_id option_id, const char *gmsgid, ...)
   va_start (ap, gmsgid);
   rich_location richloc (line_table, input_location);
   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
-					 gmsgid, &ap, DK_WARNING);
+					 gmsgid, &ap,
+					 diagnostics::kind::warning);
   va_end (ap);
   return ret;
 }
@@ -183,7 +186,8 @@ warning_at (location_t location,
   va_start (ap, gmsgid);
   rich_location richloc (line_table, location);
   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
-					 gmsgid, &ap, DK_WARNING);
+					 gmsgid, &ap,
+					 diagnostics::kind::warning);
   va_end (ap);
   return ret;
 }
@@ -201,7 +205,8 @@ warning_at (rich_location *richloc,
   va_list ap;
   va_start (ap, gmsgid);
   bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
-					 gmsgid, &ap, DK_WARNING);
+					 gmsgid, &ap,
+					 diagnostics::kind::warning);
   va_end (ap);
   return ret;
 }
@@ -220,7 +225,8 @@ warning_meta (rich_location *richloc,
   va_list ap;
   va_start (ap, gmsgid);
   bool ret = global_dc->diagnostic_impl (richloc, &metadata, option_id,
-					 gmsgid, &ap, DK_WARNING);
+					 gmsgid, &ap,
+					 diagnostics::kind::warning);
   va_end (ap);
   return ret;
 }
@@ -240,7 +246,7 @@ warning_n (rich_location *richloc,
   va_start (ap, plural_gmsgid);
   bool ret = global_dc->diagnostic_n_impl (richloc, nullptr, option_id, n,
 					   singular_gmsgid, plural_gmsgid,
-					   &ap, DK_WARNING);
+					   &ap, diagnostics::kind::warning);
   va_end (ap);
   return ret;
 }
@@ -261,7 +267,7 @@ warning_n (location_t location,
   rich_location richloc (line_table, location);
   bool ret = global_dc->diagnostic_n_impl (&richloc, nullptr, option_id, n,
 					   singular_gmsgid, plural_gmsgid,
-					   &ap, DK_WARNING);
+					   &ap, diagnostics::kind::warning);
   va_end (ap);
   return ret;
 }
@@ -289,7 +295,8 @@ pedwarn (location_t location,
   va_start (ap, gmsgid);
   rich_location richloc (line_table, location);
   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
-					 gmsgid, &ap, DK_PEDWARN);
+					 gmsgid, &ap,
+					 diagnostics::kind::pedwarn);
   va_end (ap);
   return ret;
 }
@@ -307,7 +314,8 @@ pedwarn (rich_location *richloc,
   va_list ap;
   va_start (ap, gmsgid);
   bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
-					 gmsgid, &ap, DK_PEDWARN);
+					 gmsgid, &ap,
+					 diagnostics::kind::pedwarn);
   va_end (ap);
   return ret;
 }
@@ -327,7 +335,7 @@ permerror (location_t location, const char *gmsgid, ...)
   va_start (ap, gmsgid);
   rich_location richloc (line_table, location);
   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
-					 DK_PERMERROR);
+					 diagnostics::kind::permerror);
   va_end (ap);
   return ret;
 }
@@ -343,7 +351,7 @@ permerror (rich_location *richloc, const char *gmsgid, ...)
   va_list ap;
   va_start (ap, gmsgid);
   bool ret = global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap,
-					 DK_PERMERROR);
+					 diagnostics::kind::permerror);
   va_end (ap);
   return ret;
 }
@@ -362,7 +370,8 @@ permerror_opt (location_t location,
   va_start (ap, gmsgid);
   rich_location richloc (line_table, location);
   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
-					 gmsgid, &ap, DK_PERMERROR);
+					 gmsgid, &ap,
+					 diagnostics::kind::permerror);
   va_end (ap);
   return ret;
 }
@@ -380,7 +389,8 @@ permerror_opt (rich_location *richloc,
   va_list ap;
   va_start (ap, gmsgid);
   bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
-					 gmsgid, &ap, DK_PERMERROR);
+					 gmsgid, &ap,
+					 diagnostics::kind::permerror);
   va_end (ap);
   return ret;
 }
@@ -394,7 +404,8 @@ error (const char *gmsgid, ...)
   va_list ap;
   va_start (ap, gmsgid);
   rich_location richloc (line_table, input_location);
-  global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap, DK_ERROR);
+  global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
+			      diagnostics::kind::error);
   va_end (ap);
 }
 
@@ -410,7 +421,7 @@ error_n (location_t location, unsigned HOST_WIDE_INT n,
   rich_location richloc (line_table, location);
   global_dc->diagnostic_n_impl (&richloc, nullptr, -1, n,
 				singular_gmsgid, plural_gmsgid,
-				&ap, DK_ERROR);
+				&ap, diagnostics::kind::error);
   va_end (ap);
 }
 
@@ -422,7 +433,8 @@ error_at (location_t loc, const char *gmsgid, ...)
   va_list ap;
   va_start (ap, gmsgid);
   rich_location richloc (line_table, loc);
-  global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap, DK_ERROR);
+  global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
+			      diagnostics::kind::error);
   va_end (ap);
 }
 
@@ -436,7 +448,8 @@ error_at (rich_location *richloc, const char *gmsgid, ...)
   auto_diagnostic_group d;
   va_list ap;
   va_start (ap, gmsgid);
-  global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap, DK_ERROR);
+  global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap,
+			      diagnostics::kind::error);
   va_end (ap);
 }
 
@@ -451,7 +464,8 @@ error_meta (rich_location *richloc, const diagnostics::metadata &metadata,
   auto_diagnostic_group d;
   va_list ap;
   va_start (ap, gmsgid);
-  global_dc->diagnostic_impl (richloc, &metadata, -1, gmsgid, &ap, DK_ERROR);
+  global_dc->diagnostic_impl (richloc, &metadata, -1, gmsgid, &ap,
+			      diagnostics::kind::error);
   va_end (ap);
 }
 
@@ -465,7 +479,8 @@ sorry (const char *gmsgid, ...)
   va_list ap;
   va_start (ap, gmsgid);
   rich_location richloc (line_table, input_location);
-  global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap, DK_SORRY);
+  global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
+			      diagnostics::kind::sorry);
   va_end (ap);
 }
 
@@ -477,7 +492,8 @@ sorry_at (location_t loc, const char *gmsgid, ...)
   va_list ap;
   va_start (ap, gmsgid);
   rich_location richloc (line_table, loc);
-  global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap, DK_SORRY);
+  global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
+			      diagnostics::kind::sorry);
   va_end (ap);
 }
 
@@ -499,7 +515,8 @@ fatal_error (location_t loc, const char *gmsgid, ...)
   va_list ap;
   va_start (ap, gmsgid);
   rich_location richloc (line_table, loc);
-  global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap, DK_FATAL);
+  global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
+			      diagnostics::kind::fatal);
   va_end (ap);
 
   gcc_unreachable ();
@@ -514,7 +531,8 @@ internal_error (const char *gmsgid, ...)
   va_list ap;
   va_start (ap, gmsgid);
   rich_location richloc (line_table, input_location);
-  global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap, DK_ICE);
+  global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
+			      diagnostics::kind::ice);
   va_end (ap);
 
   gcc_unreachable ();
@@ -530,7 +548,8 @@ internal_error_no_backtrace (const char *gmsgid, ...)
   va_list ap;
   va_start (ap, gmsgid);
   rich_location richloc (line_table, input_location);
-  global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap, DK_ICE_NOBT);
+  global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
+			      diagnostics::kind::ice_nobt);
   va_end (ap);
 
   gcc_unreachable ();
diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index 86dffdd1e320..5e2cb0e4d67a 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -389,9 +389,9 @@ diagnostics::context::execution_failed_p () const
 {
   /* Equivalent to (seen_error () || werrorcount), but on
      this context, rather than global_dc.  */
-  return (diagnostic_count (DK_ERROR)
-	  || diagnostic_count (DK_SORRY)
-	  || diagnostic_count (DK_WERROR));
+  return (diagnostic_count (kind::error)
+	  || diagnostic_count (kind::sorry)
+	  || diagnostic_count (kind::werror));
 }
 
 void
@@ -580,7 +580,7 @@ diagnostics::context::initialize_fixits_change_set ()
 void
 diagnostic_set_info_translated (diagnostic_info *diagnostic, const char *msg,
 				va_list *args, rich_location *richloc,
-				diagnostic_t kind)
+				enum diagnostics::kind kind)
 {
   gcc_assert (richloc);
   diagnostic->m_message.m_err_no = errno;
@@ -598,15 +598,32 @@ diagnostic_set_info_translated (diagnostic_info *diagnostic, const char *msg,
 void
 diagnostic_set_info (diagnostic_info *diagnostic, const char *gmsgid,
 		     va_list *args, rich_location *richloc,
-		     diagnostic_t kind)
+		     enum diagnostics::kind kind)
 {
   gcc_assert (richloc);
   diagnostic_set_info_translated (diagnostic, _(gmsgid), args, richloc, kind);
 }
 
+namespace diagnostics {
+
+static const char *const diagnostic_kind_text[] = {
+#define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T),
+#include "diagnostics/kinds.def"
+#undef DEFINE_DIAGNOSTIC_KIND
+  "must-not-happen"
+};
+
+/* Get unlocalized string describing KIND.  */
+
+const char *
+get_text_for_kind (enum kind kind)
+{
+  return diagnostic_kind_text[static_cast<int> (kind)];
+}
+
 static const char *const diagnostic_kind_color[] = {
 #define DEFINE_DIAGNOSTIC_KIND(K, T, C) (C),
-#include "diagnostic.def"
+#include "diagnostics/kinds.def"
 #undef DEFINE_DIAGNOSTIC_KIND
   nullptr
 };
@@ -615,11 +632,13 @@ static const char *const diagnostic_kind_color[] = {
    Result could be nullptr.  */
 
 const char *
-diagnostic_get_color_for_kind (diagnostic_t kind)
+get_color_for_kind (enum kind kind)
 {
-  return diagnostic_kind_color[kind];
+  return diagnostic_kind_color[static_cast<int> (kind)];
 }
 
+} // namespace diagnostics
+
 /* Given an expanded_location, convert the column (which is in 1-based bytes)
    to the requested units, without converting the origin.
    Return -1 if the column is invalid (<= 0).  */
@@ -709,21 +728,6 @@ location_print_policy (const diagnostics::text_sink &text_output)
 {
 }
 
-static const char *const diagnostic_kind_text[] = {
-#define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T),
-#include "diagnostic.def"
-#undef DEFINE_DIAGNOSTIC_KIND
-  "must-not-happen"
-};
-
-/* Get unlocalized string describing KIND.  */
-
-const char *
-get_diagnostic_kind_text (diagnostic_t kind)
-{
-  return diagnostic_kind_text[kind];
-}
-
 /* Functions at which to stop the backtrace print.  It's not
    particularly helpful to print the callers of these functions.  */
 
@@ -827,9 +831,9 @@ diagnostics::context::check_max_errors (bool flush)
   if (!m_max_errors)
     return;
 
-  int count = (diagnostic_count (DK_ERROR)
-	       + diagnostic_count (DK_SORRY)
-	       + diagnostic_count (DK_WERROR));
+  int count = (diagnostic_count (kind::error)
+	       + diagnostic_count (kind::sorry)
+	       + diagnostic_count (kind::werror));
 
   if (count >= m_max_errors)
     {
@@ -846,18 +850,18 @@ diagnostics::context::check_max_errors (bool flush)
    is written out.  This function does not always return.  */
 
 void
-diagnostics::context::action_after_output (diagnostic_t diag_kind)
+diagnostics::context::action_after_output (enum kind diag_kind)
 {
   switch (diag_kind)
     {
-    case DK_DEBUG:
-    case DK_NOTE:
-    case DK_ANACHRONISM:
-    case DK_WARNING:
+    case kind::debug:
+    case kind::note:
+    case kind::anachronism:
+    case kind::warning:
       break;
 
-    case DK_ERROR:
-    case DK_SORRY:
+    case kind::error:
+    case kind::sorry:
       if (m_abort_on_error)
 	real_abort ();
       if (m_fatal_errors)
@@ -868,8 +872,8 @@ diagnostics::context::action_after_output (diagnostic_t diag_kind)
 	}
       break;
 
-    case DK_ICE:
-    case DK_ICE_NOBT:
+    case kind::ice:
+    case kind::ice_nobt:
       {
 	/* Attempt to ensure that any outputs are flushed e.g. that .sarif
 	   files are written out.
@@ -882,7 +886,7 @@ diagnostics::context::action_after_output (diagnostic_t diag_kind)
 	  }
 
 	struct backtrace_state *state = nullptr;
-	if (diag_kind == DK_ICE)
+	if (diag_kind == kind::ice)
 	  state = backtrace_create_state (nullptr, 0, bt_err_callback, nullptr);
 	int count = 0;
 	if (state != nullptr)
@@ -907,7 +911,7 @@ diagnostics::context::action_after_output (diagnostic_t diag_kind)
 	exit (ICE_EXIT_CODE);
       }
 
-    case DK_FATAL:
+    case kind::fatal:
       if (m_abort_on_error)
 	real_abort ();
       fnotice (stderr, "compilation terminated.\n");
@@ -1127,26 +1131,26 @@ diagnostics::context::diagnostic_enabled (diagnostic_info *diagnostic)
     return false;
 
   /* This tests for #pragma diagnostic changes.  */
-  diagnostic_t diag_class
+  enum kind diag_class
     = m_option_classifier.update_effective_level_from_pragmas (diagnostic);
 
   /* This tests if the user provided the appropriate -Werror=foo
      option.  */
-  if (diag_class == DK_UNSPECIFIED
+  if (diag_class == kind::unspecified
       && !option_unspecified_p (diagnostic->m_option_id))
     {
-      const diagnostic_t new_kind
+      const enum kind new_kind
 	= m_option_classifier.get_current_override (diagnostic->m_option_id);
-      if (new_kind != DK_ANY)
-	/* DK_ANY means the diagnostic is not to be ignored, but we don't want
-	   to change it specifically to DK_ERROR or DK_WARNING; we want to
+      if (new_kind != kind::any)
+	/* kind::any means the diagnostic is not to be ignored, but we don't want
+	   to change it specifically to kind::error or kind::warning; we want to
 	   preserve whatever the caller has specified.  */
 	diagnostic->m_kind = new_kind;
     }
 
   /* This allows for future extensions, like temporarily disabling
      warnings for ranges of source code.  */
-  if (diagnostic->m_kind == DK_IGNORED)
+  if (diagnostic->m_kind == kind::ignored)
     return false;
 
   return true;
@@ -1166,7 +1170,7 @@ diagnostics::context::warning_enabled_at (location_t loc,
   diagnostic.m_option_id = opt_id;
   diagnostic.m_richloc = &richloc;
   diagnostic.m_message.m_richloc = &richloc;
-  diagnostic.m_kind = DK_WARNING;
+  diagnostic.m_kind = kind::warning;
   return diagnostic_enabled (&diagnostic);
 }
 
@@ -1174,7 +1178,7 @@ diagnostics::context::warning_enabled_at (location_t loc,
 
 bool
 diagnostics::context::
-emit_diagnostic_with_group (diagnostic_t kind,
+emit_diagnostic_with_group (enum kind kind,
 			    rich_location &richloc,
 			    const diagnostics::metadata *metadata,
 			    diagnostics::option_id opt_id,
@@ -1197,7 +1201,7 @@ emit_diagnostic_with_group (diagnostic_t kind,
 
 bool
 diagnostics::context::
-emit_diagnostic_with_group_va (diagnostic_t kind,
+emit_diagnostic_with_group_va (enum kind kind,
 			       rich_location &richloc,
 			       const diagnostics::metadata *metadata,
 			       diagnostics::option_id opt_id,
@@ -1222,7 +1226,7 @@ emit_diagnostic_with_group_va (diagnostic_t kind,
 bool
 diagnostics::context::report_diagnostic (diagnostic_info *diagnostic)
 {
-  diagnostic_t orig_diag_kind = diagnostic->m_kind;
+  enum kind orig_diag_kind = diagnostic->m_kind;
 
   /* Every call to report_diagnostic should be within a
      begin_group/end_group pair so that output formats can reliably
@@ -1231,8 +1235,8 @@ diagnostics::context::report_diagnostic (diagnostic_info *diagnostic)
 
   /* Give preference to being able to inhibit warnings, before they
      get reclassified to something else.  */
-  bool was_warning = (diagnostic->m_kind == DK_WARNING
-		      || diagnostic->m_kind == DK_PEDWARN);
+  bool was_warning = (diagnostic->m_kind == kind::warning
+		      || diagnostic->m_kind == kind::pedwarn);
   if (was_warning && m_inhibit_warnings)
     {
       inhibit_notes_in_group ();
@@ -1242,15 +1246,15 @@ diagnostics::context::report_diagnostic (diagnostic_info *diagnostic)
   if (m_adjust_diagnostic_info)
     m_adjust_diagnostic_info (this, diagnostic);
 
-  if (diagnostic->m_kind == DK_PEDWARN)
+  if (diagnostic->m_kind == kind::pedwarn)
     {
-      diagnostic->m_kind = m_pedantic_errors ? DK_ERROR : DK_WARNING;
+      diagnostic->m_kind = m_pedantic_errors ? kind::error : kind::warning;
 
       /* We do this to avoid giving the message for -pedantic-errors.  */
       orig_diag_kind = diagnostic->m_kind;
     }
 
-  if (diagnostic->m_kind == DK_NOTE && m_inhibit_notes_p)
+  if (diagnostic->m_kind == kind::note && m_inhibit_notes_p)
     return false;
 
   /* If the user requested that warnings be treated as errors, so be
@@ -1258,8 +1262,8 @@ diagnostics::context::report_diagnostic (diagnostic_info *diagnostic)
      individual warnings can be overridden back to warnings with
      -Wno-error=*.  */
   if (m_warning_as_error_requested
-      && diagnostic->m_kind == DK_WARNING)
-    diagnostic->m_kind = DK_ERROR;
+      && diagnostic->m_kind == kind::warning)
+    diagnostic->m_kind = kind::error;
 
   diagnostic->m_message.m_data = &diagnostic->m_x_data;
 
@@ -1272,7 +1276,7 @@ diagnostics::context::report_diagnostic (diagnostic_info *diagnostic)
       return false;
     }
 
-  if ((was_warning || diagnostic->m_kind == DK_WARNING)
+  if ((was_warning || diagnostic->m_kind == kind::warning)
       && ((!m_warn_system_headers
 	   && diagnostic->m_iinfo.m_allsyslocs)
 	  || m_inhibit_warnings))
@@ -1280,11 +1284,11 @@ diagnostics::context::report_diagnostic (diagnostic_info *diagnostic)
        inlining stack (if there is one) are in system headers.  */
     return false;
 
-  if (diagnostic->m_kind == DK_NOTE && notes_inhibited_in_group ())
+  if (diagnostic->m_kind == kind::note && notes_inhibited_in_group ())
     /* Bail for all the notes in the diagnostic_group that started to inhibit notes.  */
     return false;
 
-  if (diagnostic->m_kind != DK_NOTE && diagnostic->m_kind != DK_ICE)
+  if (diagnostic->m_kind != kind::note && diagnostic->m_kind != kind::ice)
     check_max_errors (false);
 
   if (m_lock > 0)
@@ -1292,7 +1296,8 @@ diagnostics::context::report_diagnostic (diagnostic_info *diagnostic)
       /* If we're reporting an ICE in the middle of some other error,
 	 try to flush out the previous error, then let this one
 	 through.  Don't do this more than once.  */
-      if ((diagnostic->m_kind == DK_ICE || diagnostic->m_kind == DK_ICE_NOBT)
+      if ((diagnostic->m_kind == kind::ice
+	   || diagnostic->m_kind == kind::ice_nobt)
 	  && m_lock == 1)
 	pp_newline_and_flush (m_reference_printer);
       else
@@ -1304,14 +1309,14 @@ diagnostics::context::report_diagnostic (diagnostic_info *diagnostic)
 
   m_lock++;
 
-  if (diagnostic->m_kind == DK_ICE || diagnostic->m_kind == DK_ICE_NOBT)
+  if (diagnostic->m_kind == kind::ice || diagnostic->m_kind == kind::ice_nobt)
     {
       /* When not checking, ICEs are converted to fatal errors when an
 	 error has already occurred.  This is counteracted by
 	 abort_on_error.  */
       if (!CHECKING_P
-	  && (diagnostic_count (DK_ERROR) > 0
-	      || diagnostic_count (DK_SORRY) > 0)
+	  && (diagnostic_count (kind::error) > 0
+	      || diagnostic_count (kind::sorry) > 0)
 	  && !m_abort_on_error)
 	{
 	  expanded_location s
@@ -1329,15 +1334,15 @@ diagnostics::context::report_diagnostic (diagnostic_info *diagnostic)
   /* Increment the counter for the appropriate diagnostic kind, either
      within this context, or within the diagnostic_buffer.  */
   {
-    const diagnostic_t kind_for_count =
-      ((diagnostic->m_kind == DK_ERROR && orig_diag_kind == DK_WARNING)
-       ? DK_WERROR
+    const enum kind kind_for_count =
+      ((diagnostic->m_kind == kind::error && orig_diag_kind == kind::warning)
+       ? kind::werror
        : diagnostic->m_kind);
-    diagnostics::counters &counters
+    counters &cs
       = (m_diagnostic_buffer
 	 ? m_diagnostic_buffer->m_diagnostic_counters
 	 : m_diagnostic_counters);
-    ++counters.m_count_for_kind[kind_for_count];
+    ++cs.m_count_for_kind[static_cast<size_t> (kind_for_count)];
   }
 
   /* Is this the initial diagnostic within the stack of groups?  */
@@ -1395,8 +1400,8 @@ diagnostics::context::report_diagnostic (diagnostic_info *diagnostic)
       break;
     }
   if (m_diagnostic_buffer == nullptr
-      || diagnostic->m_kind == DK_ICE
-      || diagnostic->m_kind == DK_ICE_NOBT)
+      || diagnostic->m_kind == kind::ice
+      || diagnostic->m_kind == kind::ice_nobt)
     action_after_output (diagnostic->m_kind);
   diagnostic->m_x_data = nullptr;
 
@@ -1495,19 +1500,19 @@ diagnostics::context::diagnostic_impl (rich_location *richloc,
 				     const diagnostics::metadata *metadata,
 				     diagnostics::option_id opt_id,
 				     const char *gmsgid,
-				     va_list *ap, diagnostic_t kind)
+				     va_list *ap, enum kind kind)
 {
   diagnostic_info diagnostic;
-  if (kind == DK_PERMERROR)
+  if (kind == kind::permerror)
     {
       diagnostic_set_info (&diagnostic, gmsgid, ap, richloc,
-			   m_permissive ? DK_WARNING : DK_ERROR);
+			   m_permissive ? kind::warning : kind::error);
       diagnostic.m_option_id = (opt_id.m_idx != -1 ? opt_id : m_opt_permissive);
     }
   else
     {
       diagnostic_set_info (&diagnostic, gmsgid, ap, richloc, kind);
-      if (kind == DK_WARNING || kind == DK_PEDWARN)
+      if (kind == kind::warning || kind == kind::pedwarn)
 	diagnostic.m_option_id = opt_id;
     }
   diagnostic.m_metadata = metadata;
@@ -1523,7 +1528,7 @@ diagnostics::context::diagnostic_n_impl (rich_location *richloc,
 				       unsigned HOST_WIDE_INT n,
 				       const char *singular_gmsgid,
 				       const char *plural_gmsgid,
-				       va_list *ap, diagnostic_t kind)
+				       va_list *ap, enum kind kind)
 {
   diagnostic_info diagnostic;
   unsigned long gtn;
@@ -1538,7 +1543,7 @@ diagnostics::context::diagnostic_n_impl (rich_location *richloc,
 
   const char *text = ngettext (singular_gmsgid, plural_gmsgid, gtn);
   diagnostic_set_info_translated (&diagnostic, text, ap, richloc, kind);
-  if (kind == DK_WARNING)
+  if (kind == kind::warning)
     diagnostic.m_option_id = opt_id;
   diagnostic.m_metadata = metadata;
   return report_diagnostic (&diagnostic);
@@ -1573,7 +1578,7 @@ diagnostics::context::error_recursion ()
 
   /* Call action_after_output to get the "please submit a bug report"
      message.  */
-  action_after_output (DK_ICE);
+  action_after_output (kind::ice);
 
   /* Do not use gcc_unreachable here; that goes through internal_error
      and therefore would cause infinite recursion.  */
@@ -1599,7 +1604,7 @@ fancy_abort (const char *file, int line, const char *function)
   if (global_dc->get_reference_printer () == nullptr)
     {
       /* Print the error message.  */
-      fnotice (stderr, diagnostic_kind_text[DK_ICE]);
+      fnotice (stderr, diagnostics::get_text_for_kind (diagnostics::kind::ice));
       fnotice (stderr, "in %s, at %s:%d", function, trim_filename (file), line);
       fputc ('\n', stderr);
 
@@ -1754,12 +1759,12 @@ diagnostics::counters::dump (FILE *out, int indent) const
 {
   fprintf (out, "%*scounts:\n", indent, "");
   bool none = true;
-  for (int i = 0; i < DK_LAST_DIAGNOSTIC_KIND; i++)
+  for (int i = 0; i < static_cast<int> (kind::last_diagnostic_kind); i++)
     if (m_count_for_kind[i] > 0)
       {
 	fprintf (out, "%*s%s%i\n",
 		 indent + 2, "",
-		 get_diagnostic_kind_text (static_cast<diagnostic_t> (i)),
+		 get_text_for_kind (static_cast<enum kind> (i)),
 		 m_count_for_kind[i]);
 	none = false;
       }
@@ -1770,7 +1775,7 @@ diagnostics::counters::dump (FILE *out, int indent) const
 void
 diagnostics::counters::move_to (diagnostics::counters &dest)
 {
-  for (int i = 0; i < DK_LAST_DIAGNOSTIC_KIND; i++)
+  for (int i = 0; i < static_cast<int> (kind::last_diagnostic_kind); i++)
     dest.m_count_for_kind[i] += m_count_for_kind[i];
   clear ();
 }
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index 69bc798c9b18..a0ba11537083 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -167,13 +167,13 @@ extern diagnostics::context *global_dc;
 
 /* The number of errors that have been issued so far.  Ideally, these
    would take a diagnostics::context as an argument.  */
-#define errorcount global_dc->diagnostic_count (DK_ERROR)
+#define errorcount global_dc->diagnostic_count (diagnostics::kind::error)
 /* Similarly, but for warnings.  */
-#define warningcount global_dc->diagnostic_count (DK_WARNING)
+#define warningcount global_dc->diagnostic_count (diagnostics::kind::warning)
 /* Similarly, but for warnings promoted to errors.  */
-#define werrorcount global_dc->diagnostic_count (DK_WERROR)
+#define werrorcount global_dc->diagnostic_count (diagnostics::kind::werror)
 /* Similarly, but for sorrys.  */
-#define sorrycount global_dc->diagnostic_count (DK_SORRY)
+#define sorrycount global_dc->diagnostic_count (diagnostics::kind::sorry)
 
 /* Returns nonzero if warnings should be emitted.  */
 #define diagnostic_report_warnings_p(DC, LOC)				\
@@ -220,7 +220,7 @@ inline void
 diagnostic_show_locus (diagnostics::context *context,
 		       const diagnostics::source_printing_options &opts,
 		       rich_location *richloc,
-		       diagnostic_t diagnostic_kind,
+		       enum diagnostics::kind diagnostic_kind,
 		       pretty_printer *pp,
 		       diagnostics::source_effect_info *effect_info = nullptr)
 {
@@ -234,7 +234,7 @@ inline void
 diagnostic_show_locus_as_html (diagnostics::context *context,
 			       const diagnostics::source_printing_options &opts,
 			       rich_location *richloc,
-			       diagnostic_t diagnostic_kind,
+			       enum diagnostics::kind diagnostic_kind,
 			       xml::printer &xp,
 			       diagnostics::source_effect_info *effect_info = nullptr,
 			       diagnostics::html_label_writer *label_writer = nullptr)
@@ -269,10 +269,10 @@ diagnostic_initialize_input_context (diagnostics::context *context,
 }
 
 /* Force diagnostics controlled by OPTIDX to be kind KIND.  */
-inline diagnostic_t
+inline diagnostics::kind
 diagnostic_classify_diagnostic (diagnostics::context *context,
 				diagnostics::option_id opt_id,
-				diagnostic_t kind,
+				enum diagnostics::kind kind,
 				location_t where)
 {
   return context->classify_diagnostic (opt_id, kind, where);
@@ -310,10 +310,10 @@ diagnostic_report_diagnostic (diagnostics::context *context,
 
 #ifdef ATTRIBUTE_GCC_DIAG
 extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *,
-				 rich_location *, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0);
+				 rich_location *, enum diagnostics::kind) ATTRIBUTE_GCC_DIAG(2,0);
 extern void diagnostic_set_info_translated (diagnostic_info *, const char *,
 					    va_list *, rich_location *,
-					    diagnostic_t)
+					    enum diagnostics::kind)
      ATTRIBUTE_GCC_DIAG(2,0);
 #endif
 
@@ -327,7 +327,7 @@ void default_start_span_fn (const diagnostics::location_print_policy &,
 			    expanded_location);
 void default_text_finalizer (diagnostics::text_sink &,
 			     const diagnostic_info *,
-			     diagnostic_t);
+			     enum diagnostics::kind);
 } // namespace diagnostics
 
 void diagnostic_set_caret_max_width (diagnostics::context *context, int value);
@@ -379,8 +379,6 @@ diagnostic_same_line (const diagnostics::context *context,
 	      > abs (s1.column - s2.column)));
 }
 
-extern const char *diagnostic_get_color_for_kind (diagnostic_t kind);
-
 /* Pure text formatting support functions.  */
 
 extern char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
@@ -402,8 +400,6 @@ option_unspecified_p (diagnostics::option_id opt_id)
 
 extern char *get_cwe_url (int cwe);
 
-extern const char *get_diagnostic_kind_text (diagnostic_t kind);
-
 namespace diagnostics {
 
 const char *maybe_line_and_column (int line, int col);
diff --git a/gcc/diagnostics/buffering.cc b/gcc/diagnostics/buffering.cc
index 53afc90f02b7..29f039febad2 100644
--- a/gcc/diagnostics/buffering.cc
+++ b/gcc/diagnostics/buffering.cc
@@ -89,14 +89,14 @@ void
 context::flush_diagnostic_buffer (buffer &buffer_)
 {
   bool had_errors
-    = (buffer_.m_diagnostic_counters.m_count_for_kind[DK_ERROR] > 0
-       || buffer_.m_diagnostic_counters.m_count_for_kind[DK_WERROR] > 0);
+    = (buffer_.diagnostic_count (kind::error) > 0
+       || buffer_.diagnostic_count (kind::werror) > 0);
   if (buffer_.m_per_sink_buffers)
     for (auto per_sink_buffer_ : *buffer_.m_per_sink_buffers)
       per_sink_buffer_->flush ();
   buffer_.m_diagnostic_counters.move_to (m_diagnostic_counters);
 
-  action_after_output (had_errors ? DK_ERROR : DK_WARNING);
+  action_after_output (had_errors ? kind::error : kind::warning);
   check_max_errors (true);
 }
 
diff --git a/gcc/diagnostics/buffering.h b/gcc/diagnostics/buffering.h
index 1e65b4e37b6f..c3ac070ba00b 100644
--- a/gcc/diagnostics/buffering.h
+++ b/gcc/diagnostics/buffering.h
@@ -66,7 +66,7 @@ class buffer
   void dump (FILE *out, int indent) const;
   void DEBUG_FUNCTION dump () const { dump (stderr, 0); }
 
-  int diagnostic_count (diagnostic_t kind) const
+  int diagnostic_count (enum kind kind) const
   {
     return m_diagnostic_counters.get_count (kind);
   }
diff --git a/gcc/diagnostics/context.h b/gcc/diagnostics/context.h
index 78663cdf1e56..c985d51f4706 100644
--- a/gcc/diagnostics/context.h
+++ b/gcc/diagnostics/context.h
@@ -46,7 +46,7 @@ using start_span_fn = void (*) (const location_print_policy &,
 
 typedef void (*text_finalizer_fn) (text_sink &,
 				   const diagnostic_info *,
-				   diagnostic_t);
+				   enum kind);
 
 /* Abstract base class for the diagnostic subsystem to make queries
    about command-line options.  */
@@ -67,8 +67,8 @@ public:
      May return NULL if no name is to be printed.
      May be passed 0 as well as the index of a particular option.  */
   virtual char *make_option_name (option_id opt_id,
-				  diagnostic_t orig_diag_kind,
-				  diagnostic_t diag_kind) const = 0;
+				  enum kind orig_diag_kind,
+				  enum kind diag_kind) const = 0;
 
   /* Return malloced memory for a URL describing the option that controls
      a diagnostic.
@@ -205,13 +205,13 @@ public:
   void
   print (pretty_printer &pp,
 	 const rich_location &richloc,
-	 diagnostic_t diagnostic_kind,
+	 enum kind diagnostic_kind,
 	 source_effect_info *effect_info) const;
 
   void
   print_as_html (xml::printer &xp,
 		 const rich_location &richloc,
-		 diagnostic_t diagnostic_kind,
+		 enum kind diagnostic_kind,
 		 source_effect_info *effect_info,
 		 html_label_writer *label_writer) const;
 
@@ -269,12 +269,15 @@ struct counters
   void dump (FILE *out, int indent) const;
   void DEBUG_FUNCTION dump () const { dump (stderr, 0); }
 
-  int get_count (diagnostic_t kind) const { return m_count_for_kind[kind]; }
+  int get_count (enum kind kind) const
+  {
+    return m_count_for_kind[static_cast<size_t> (kind)];
+  }
 
   void move_to (counters &dest);
   void clear ();
 
-  int m_count_for_kind[DK_LAST_DIAGNOSTIC_KIND];
+  int m_count_for_kind[static_cast<size_t> (kind::last_diagnostic_kind)];
 };
 
 /* This class encapsulates the state of the diagnostics subsystem
@@ -370,13 +373,13 @@ public:
     return m_option_classifier.option_unspecified_p (opt_id);
   }
 
-  bool emit_diagnostic_with_group (diagnostic_t kind,
+  bool emit_diagnostic_with_group (enum kind kind,
 				   rich_location &richloc,
 				   const metadata *metadata,
 				   option_id opt_id,
 				   const char *gmsgid, ...)
     ATTRIBUTE_GCC_DIAG(6,7);
-  bool emit_diagnostic_with_group_va (diagnostic_t kind,
+  bool emit_diagnostic_with_group_va (enum kind kind,
 				      rich_location &richloc,
 				      const metadata *metadata,
 				      option_id opt_id,
@@ -391,9 +394,9 @@ public:
   void
   report_global_digraph (const digraphs::lazy_digraph &);
 
-  diagnostic_t
+  enum kind
   classify_diagnostic (option_id opt_id,
-		       diagnostic_t new_kind,
+		       enum kind new_kind,
 		       location_t where)
   {
     return m_option_classifier.classify_diagnostic (this,
@@ -413,12 +416,12 @@ public:
 
   void maybe_show_locus (const rich_location &richloc,
 			 const source_printing_options &opts,
-			 diagnostic_t diagnostic_kind,
+			 enum kind diagnostic_kind,
 			 pretty_printer &pp,
 			 source_effect_info *effect_info);
   void maybe_show_locus_as_html (const rich_location &richloc,
 				 const source_printing_options &opts,
-				 diagnostic_t diagnostic_kind,
+				 enum kind diagnostic_kind,
 				 xml::printer &xp,
 				 source_effect_info *effect_info,
 				 html_label_writer *label_writer);
@@ -498,11 +501,11 @@ public:
 
   text_art::theme *get_diagram_theme () const { return m_diagrams.m_theme; }
 
-  int &diagnostic_count (diagnostic_t kind)
+  int &diagnostic_count (enum kind kind)
   {
-    return m_diagnostic_counters.m_count_for_kind[kind];
+    return m_diagnostic_counters.m_count_for_kind[static_cast<size_t> (kind)];
   }
-  int diagnostic_count (diagnostic_t kind) const
+  int diagnostic_count (enum kind kind) const
   {
     return m_diagnostic_counters.get_count (kind);
   }
@@ -516,8 +519,8 @@ public:
   }
 
   inline char *make_option_name (option_id opt_id,
-				 diagnostic_t orig_diag_kind,
-				 diagnostic_t diag_kind) const
+				 enum kind orig_diag_kind,
+				 enum kind diag_kind) const
   {
     if (!m_option_mgr)
       return nullptr;
@@ -544,11 +547,11 @@ public:
 
   bool diagnostic_impl (rich_location *, const metadata *,
 			option_id, const char *,
-			va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(5,0);
+			va_list *, enum kind) ATTRIBUTE_GCC_DIAG(5,0);
   bool diagnostic_n_impl (rich_location *, const metadata *,
 			  option_id, unsigned HOST_WIDE_INT,
 			  const char *, const char *, va_list *,
-			  diagnostic_t) ATTRIBUTE_GCC_DIAG(7,0);
+			  enum kind) ATTRIBUTE_GCC_DIAG(7,0);
 
   int get_diagnostic_nesting_level () const
   {
@@ -595,7 +598,7 @@ public:
 
   bool supports_fnotice_on_stderr_p () const;
 
-  /* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher.  */
+  /* Raise SIGABRT on any diagnostic of severity kind::error or higher.  */
   void
   set_abort_on_error (bool val)
   {
@@ -649,7 +652,7 @@ private:
   void get_any_inlining_info (diagnostic_info *diagnostic);
 
   void check_max_errors (bool flush);
-  void action_after_output (diagnostic_t diag_kind);
+  void action_after_output (enum kind diag_kind);
 
   /* Data members.
      Ideally, all of these would be private.  */
diff --git a/gcc/diagnostics/diagnostic-info.h b/gcc/diagnostics/diagnostic-info.h
index 621f95a856a6..052fef52f1eb 100644
--- a/gcc/diagnostics/diagnostic-info.h
+++ b/gcc/diagnostics/diagnostic-info.h
@@ -26,7 +26,7 @@ class metadata;
 
 /* A diagnostic is described by the MESSAGE to send, the FILE and LINE of
    its context and its KIND (ice, error, warning, note, ...)  See complete
-   list in diagnostic.def.  */
+   list in diagnostics/kinds.def.  */
 
 struct diagnostic_info
 {
@@ -53,7 +53,7 @@ struct diagnostic_info
   /* Auxiliary data for client.  */
   void *m_x_data;
   /* The kind of diagnostic it is about.  */
-  diagnostic_t m_kind;
+  kind m_kind;
   /* Which OPT_* directly controls this diagnostic.  */
   option_id m_option_id;
 
diff --git a/gcc/diagnostics/html-sink.cc b/gcc/diagnostics/html-sink.cc
index f62a3ca4cf44..a0202546a59f 100644
--- a/gcc/diagnostics/html-sink.cc
+++ b/gcc/diagnostics/html-sink.cc
@@ -120,7 +120,7 @@ public:
   set_main_input_filename (const char *name);
 
   void on_report_diagnostic (const diagnostic_info &diagnostic,
-			     diagnostic_t orig_diag_kind,
+			     enum kind orig_diag_kind,
 			     html_sink_buffer *buffer);
   void emit_diagram (const diagram &d);
   void emit_global_graph (const digraphs::lazy_digraph &);
@@ -161,7 +161,7 @@ private:
 
   std::unique_ptr<xml::element>
   make_element_for_diagnostic (const diagnostic_info &diagnostic,
-			       diagnostic_t orig_diag_kind,
+			       enum kind orig_diag_kind,
 			       bool alert);
 
   std::unique_ptr<xml::element>
@@ -496,10 +496,10 @@ html_builder::add_stylesheet (std::string url)
 
 void
 html_builder::on_report_diagnostic (const diagnostic_info &diagnostic,
-				    diagnostic_t orig_diag_kind,
+				    enum kind orig_diag_kind,
 				    html_sink_buffer *buffer)
 {
-  if (diagnostic.m_kind == DK_ICE || diagnostic.m_kind == DK_ICE_NOBT)
+  if (diagnostic.m_kind == kind::ice || diagnostic.m_kind == kind::ice_nobt)
     {
       /* Print a header for the remaining output to stderr, and
 	 return, attempting to print the usual ICE messages to
@@ -722,23 +722,23 @@ private:
 
 /* See https://pf3.patternfly.org/v3/pattern-library/widgets/#alerts */
 static const char *
-get_pf_class_for_alert_div (diagnostic_t diag_kind)
+get_pf_class_for_alert_div (enum kind diag_kind)
 {
   switch (diag_kind)
     {
-    case DK_DEBUG:
-    case DK_NOTE:
+    case kind::debug:
+    case kind::note:
       return "alert alert-info";
 
-    case DK_ANACHRONISM:
-    case DK_WARNING:
+    case kind::anachronism:
+    case kind::warning:
       return "alert alert-warning";
 
-    case DK_ERROR:
-    case DK_SORRY:
-    case DK_ICE:
-    case DK_ICE_NOBT:
-    case DK_FATAL:
+    case kind::error:
+    case kind::sorry:
+    case kind::ice:
+    case kind::ice_nobt:
+    case kind::fatal:
       return "alert alert-danger";
 
     default:
@@ -747,23 +747,23 @@ get_pf_class_for_alert_div (diagnostic_t diag_kind)
 }
 
 static const char *
-get_pf_class_for_alert_icon (diagnostic_t diag_kind)
+get_pf_class_for_alert_icon (enum kind diag_kind)
 {
   switch (diag_kind)
     {
-    case DK_DEBUG:
-    case DK_NOTE:
+    case kind::debug:
+    case kind::note:
       return "pficon pficon-info";
 
-    case DK_ANACHRONISM:
-    case DK_WARNING:
+    case kind::anachronism:
+    case kind::warning:
       return "pficon pficon-warning-triangle-o";
 
-    case DK_ERROR:
-    case DK_SORRY:
-    case DK_ICE:
-    case DK_ICE_NOBT:
-    case DK_FATAL:
+    case kind::error:
+    case kind::sorry:
+    case kind::ice:
+    case kind::ice_nobt:
+    case kind::fatal:
       return "pficon pficon-error-circle-o";
 
     default:
@@ -946,7 +946,7 @@ private:
 
 std::unique_ptr<xml::element>
 html_builder::make_element_for_diagnostic (const diagnostic_info &diagnostic,
-					   diagnostic_t orig_diag_kind,
+					   enum kind orig_diag_kind,
 					   bool alert)
 {
   const int diag_idx = m_next_diag_id++;
@@ -1004,7 +1004,7 @@ html_builder::make_element_for_diagnostic (const diagnostic_info &diagnostic,
   if (show_severity)
   {
     xp.push_tag ("strong");
-    xp.add_text (_(get_diagnostic_kind_text (diagnostic.m_kind)));
+    xp.add_text (_(get_text_for_kind (diagnostic.m_kind)));
     xp.pop_tag ("strong");
     xp.add_text (" ");
   }
@@ -1360,7 +1360,7 @@ public:
   }
   void
   on_report_diagnostic (const diagnostic_info &diagnostic,
-			diagnostic_t orig_diag_kind) final override
+			enum kind orig_diag_kind) final override
   {
     m_builder.on_report_diagnostic (diagnostic, orig_diag_kind, m_buffer);
   }
@@ -1463,7 +1463,7 @@ open_html_output_file (context &dc,
     {
       rich_location richloc (line_maps, UNKNOWN_LOCATION);
       dc.emit_diagnostic_with_group
-	(DK_ERROR, richloc, nullptr, 0,
+	(kind::error, richloc, nullptr, 0,
 	 "unable to determine filename for HTML output");
       return output_file ();
     }
@@ -1476,7 +1476,7 @@ open_html_output_file (context &dc,
     {
       rich_location richloc (line_maps, UNKNOWN_LOCATION);
       dc.emit_diagnostic_with_group
-	(DK_ERROR, richloc, nullptr, 0,
+	(kind::error, richloc, nullptr, 0,
 	 "unable to open %qs for HTML output: %m",
 	 filename.get ());
       return output_file ();
@@ -1620,7 +1620,7 @@ test_simple_log ()
   test_html_context dc;
 
   rich_location richloc (line_table, UNKNOWN_LOCATION);
-  dc.report (DK_ERROR, richloc, nullptr, 0, "this is a test: %qs", "foo");
+  dc.report (kind::error, richloc, nullptr, 0, "this is a test: %qs", "foo");
 
   const xml::document &doc  = dc.get_document ();
 
diff --git a/gcc/diagnostic.def b/gcc/diagnostics/kinds.def
similarity index 53%
rename from gcc/diagnostic.def
rename to gcc/diagnostics/kinds.def
index ab2185c2cd07..2a0a0a6c7095 100644
--- a/gcc/diagnostic.def
+++ b/gcc/diagnostics/kinds.def
@@ -16,40 +16,40 @@ You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
-/* DK_UNSPECIFIED must be first so it has a value of zero.  We never
+/* kind::unspecified must be first so it has a value of zero.  We never
    assign this kind to an actual diagnostic, we only use this in
    variables that can hold a kind, to mean they have yet to have a
    kind specified.  I.e. they're uninitialized.  Within the diagnostic
    machinery, this kind also means "don't change the existing kind",
    meaning "no change is specified".  */
-DEFINE_DIAGNOSTIC_KIND (DK_UNSPECIFIED, "", NULL)
+DEFINE_DIAGNOSTIC_KIND (unspecified, "", NULL)
 
-/* If a diagnostic is set to DK_IGNORED, it won't get reported at all.
+/* If a diagnostic is set to kind::ignored, it won't get reported at all.
    This is used by the diagnostic machinery when it wants to disable a
    diagnostic without disabling the option which causes it.  */
-DEFINE_DIAGNOSTIC_KIND (DK_IGNORED, "", NULL)
+DEFINE_DIAGNOSTIC_KIND (ignored, "", NULL)
 
 /* The remainder are real diagnostic types.  */
-DEFINE_DIAGNOSTIC_KIND (DK_FATAL, "fatal error: ", "error")
-DEFINE_DIAGNOSTIC_KIND (DK_ICE, "internal compiler error: ", "error")
-DEFINE_DIAGNOSTIC_KIND (DK_ERROR, "error: ", "error")
-DEFINE_DIAGNOSTIC_KIND (DK_SORRY, "sorry, unimplemented: ", "error")
-DEFINE_DIAGNOSTIC_KIND (DK_WARNING, "warning: ", "warning")
-DEFINE_DIAGNOSTIC_KIND (DK_ANACHRONISM, "anachronism: ", "warning")
-DEFINE_DIAGNOSTIC_KIND (DK_NOTE, "note: ", "note")
-DEFINE_DIAGNOSTIC_KIND (DK_DEBUG, "debug: ", "note")
+DEFINE_DIAGNOSTIC_KIND (fatal, "fatal error: ", "error")
+DEFINE_DIAGNOSTIC_KIND (ice, "internal compiler error: ", "error")
+DEFINE_DIAGNOSTIC_KIND (error, "error: ", "error")
+DEFINE_DIAGNOSTIC_KIND (sorry, "sorry, unimplemented: ", "error")
+DEFINE_DIAGNOSTIC_KIND (warning, "warning: ", "warning")
+DEFINE_DIAGNOSTIC_KIND (anachronism, "anachronism: ", "warning")
+DEFINE_DIAGNOSTIC_KIND (note, "note: ", "note")
+DEFINE_DIAGNOSTIC_KIND (debug, "debug: ", "note")
 
 /* For use when using the diagnostic_show_locus machinery to show
    a range of events within a path.  */
-DEFINE_DIAGNOSTIC_KIND (DK_DIAGNOSTIC_PATH, "path: ", "path")
+DEFINE_DIAGNOSTIC_KIND (path, "path: ", "path")
 
-/* These two would be re-classified as DK_WARNING or DK_ERROR, so the
+/* These two would be re-classified as kind::warning or kind::error, so the
 prefix does not matter.  */
-DEFINE_DIAGNOSTIC_KIND (DK_PEDWARN, "pedwarn: ", NULL)
-DEFINE_DIAGNOSTIC_KIND (DK_PERMERROR, "permerror: ", NULL)
-/* This one is just for counting DK_WARNING promoted to DK_ERROR
+DEFINE_DIAGNOSTIC_KIND (pedwarn, "pedwarn: ", NULL)
+DEFINE_DIAGNOSTIC_KIND (permerror, "permerror: ", NULL)
+/* This one is just for counting kind::warning promoted to kind::error
    due to -Werror and -Werror=warning.  */
-DEFINE_DIAGNOSTIC_KIND (DK_WERROR, "error: ", NULL)
-/* This is like DK_ICE, but backtrace is not printed.  Used in the driver
+DEFINE_DIAGNOSTIC_KIND (werror, "error: ", NULL)
+/* This is like kind::ICE, but backtrace is not printed.  Used in the driver
    when reporting fatal signal in the compiler.  */
-DEFINE_DIAGNOSTIC_KIND (DK_ICE_NOBT, "internal compiler error: ", "error")
+DEFINE_DIAGNOSTIC_KIND (ice_nobt, "internal compiler error: ", "error")
diff --git a/gcc/diagnostics/kinds.h b/gcc/diagnostics/kinds.h
new file mode 100644
index 000000000000..7b4a1687d0e2
--- /dev/null
+++ b/gcc/diagnostics/kinds.h
@@ -0,0 +1,45 @@
+/* An enum used to discriminate severities of diagnostics.
+   Copyright (C) 1998-2025 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#ifndef GCC_DIAGNOSTICS_KINDS_H
+#define GCC_DIAGNOSTICS_KINDS_H
+
+namespace diagnostics {
+
+/* Constants used to discriminate diagnostics.  */
+enum class kind
+{
+#define DEFINE_DIAGNOSTIC_KIND(K, msgid, C) K,
+#include "diagnostics/kinds.def"
+#undef DEFINE_DIAGNOSTIC_KIND
+  last_diagnostic_kind,
+  /* This is used for tagging pragma pops in the diagnostic
+     classification history chain.  */
+  pop,
+  /* This is used internally to note that a diagnostic is enabled
+     without mandating any specific type.  */
+  any
+};
+
+extern const char *get_text_for_kind (enum diagnostics::kind);
+extern const char *get_color_for_kind (enum diagnostics::kind);
+
+} // namespace diagnostics
+
+#endif /* ! GCC_DIAGNOSTICS_KINDS_H */
diff --git a/gcc/diagnostics/lazy-paths.cc b/gcc/diagnostics/lazy-paths.cc
index 216ad744a3b7..4934651c3229 100644
--- a/gcc/diagnostics/lazy-paths.cc
+++ b/gcc/diagnostics/lazy-paths.cc
@@ -139,8 +139,8 @@ public:
     return 0;
   }
   char *make_option_name (diagnostics::option_id,
-			  diagnostic_t,
-			  diagnostic_t) const final override
+			  enum kind,
+			  enum kind) const final override
   {
     return nullptr;
   }
@@ -175,7 +175,7 @@ test_emission (pretty_printer *event_pp)
 
     diagnostics::option_id opt_id (42); // has to be non-zero
     bool emitted
-      = dc.emit_diagnostic_with_group (DK_WARNING, rich_loc, nullptr,
+      = dc.emit_diagnostic_with_group (kind::warning, rich_loc, nullptr,
 				       opt_id,
 				       "this warning should be skipped");
     ASSERT_FALSE (emitted);
@@ -191,7 +191,7 @@ test_emission (pretty_printer *event_pp)
     ASSERT_FALSE (rich_loc.m_path.generated_p ());
 
     bool emitted
-      = dc.emit_diagnostic_with_group (DK_ERROR, rich_loc, nullptr, 0,
+      = dc.emit_diagnostic_with_group (kind::error, rich_loc, nullptr, 0,
 				       "this is a test");
     ASSERT_TRUE (emitted);
     ASSERT_TRUE (rich_loc.m_path.generated_p ());
diff --git a/gcc/diagnostics/option-classifier.cc b/gcc/diagnostics/option-classifier.cc
index d3f0985d4647..98316b46f1fe 100644
--- a/gcc/diagnostics/option-classifier.cc
+++ b/gcc/diagnostics/option-classifier.cc
@@ -30,9 +30,9 @@ void
 option_classifier::init (int n_opts)
 {
   m_n_opts = n_opts;
-  m_classify_diagnostic = XNEWVEC (diagnostic_t, n_opts);
+  m_classify_diagnostic = XNEWVEC (enum kind, n_opts);
   for (int i = 0; i < n_opts; i++)
-    m_classify_diagnostic[i] = DK_UNSPECIFIED;
+    m_classify_diagnostic[i] = kind::unspecified;
   m_push_list = vNULL;
   m_classification_history = vNULL;
 }
@@ -111,27 +111,27 @@ option_classifier::pop (location_t where)
   else
     jump_to = 0;
 
-  classification_change_t v = { where, jump_to, DK_POP };
+  classification_change_t v = { where, jump_to, kind::pop };
   m_classification_history.safe_push (v);
 }
 
 /* Interface to specify diagnostic kind overrides.  Returns the
-   previous setting, or DK_UNSPECIFIED if the parameters are out of
+   previous setting, or kind::unspecified if the parameters are out of
    range.  If OPTION_ID is zero, the new setting is for all the
    diagnostics.  */
 
-diagnostic_t
+enum kind
 option_classifier::classify_diagnostic (const context *dc,
 					option_id opt_id,
-					diagnostic_t new_kind,
+					enum kind new_kind,
 					location_t where)
 {
-  diagnostic_t old_kind;
+  enum kind old_kind;
 
   if (opt_id.m_idx < 0
       || opt_id.m_idx >= m_n_opts
-      || new_kind >= DK_LAST_DIAGNOSTIC_KIND)
-    return DK_UNSPECIFIED;
+      || new_kind >= kind::last_diagnostic_kind)
+    return kind::unspecified;
 
   old_kind = m_classify_diagnostic[opt_id.m_idx];
 
@@ -141,11 +141,11 @@ option_classifier::classify_diagnostic (const context *dc,
     {
       unsigned i;
 
-      /* Record the command-line status, so we can reset it back on DK_POP. */
-      if (old_kind == DK_UNSPECIFIED)
+      /* Record the command-line status, so we can reset it back on kind::pop. */
+      if (old_kind == kind::unspecified)
 	{
 	  old_kind = (!dc->option_enabled_p (opt_id)
-		      ? DK_IGNORED : DK_ANY);
+		      ? kind::ignored : kind::any);
 	  m_classify_diagnostic[opt_id.m_idx] = old_kind;
 	}
 
@@ -172,15 +172,15 @@ option_classifier::classify_diagnostic (const context *dc,
      #pragma GCC diagnostic
    directives recorded within this object.
 
-   Return the new kind of DIAGNOSTIC if it was updated, or DK_UNSPECIFIED
+   Return the new kind of DIAGNOSTIC if it was updated, or kind::unspecified
    otherwise.  */
 
-diagnostic_t
+enum kind
 option_classifier::
 update_effective_level_from_pragmas (diagnostic_info *diagnostic) const
 {
   if (m_classification_history.is_empty ())
-    return DK_UNSPECIFIED;
+    return kind::unspecified;
 
   /* Iterate over the locations, checking the diagnostic disposition
      for the diagnostic at each.  If it's explicitly set as opposed
@@ -197,7 +197,7 @@ update_effective_level_from_pragmas (diagnostic_info *diagnostic) const
 	  if (!linemap_location_before_p (line_table, pragloc, loc))
 	    continue;
 
-	  if (p->kind == (int) DK_POP)
+	  if (p->kind == kind::pop)
 	    {
 	      /* Move on to the next region.  */
 	      i = p->option;
@@ -208,15 +208,15 @@ update_effective_level_from_pragmas (diagnostic_info *diagnostic) const
 	  /* The option 0 is for all the diagnostics.  */
 	  if (opt_id == 0 || opt_id == diagnostic->m_option_id)
 	    {
-	      diagnostic_t kind = p->kind;
-	      if (kind != DK_UNSPECIFIED)
+	      enum kind kind = p->kind;
+	      if (kind != kind::unspecified)
 		diagnostic->m_kind = kind;
 	      return kind;
 	    }
 	}
     }
 
-  return DK_UNSPECIFIED;
+  return kind::unspecified;
 }
 
 } // namespace diagnostics
diff --git a/gcc/diagnostics/option-classifier.h b/gcc/diagnostics/option-classifier.h
index 6ed417fe70a8..bf089b6f6c30 100644
--- a/gcc/diagnostics/option-classifier.h
+++ b/gcc/diagnostics/option-classifier.h
@@ -44,22 +44,22 @@ public:
 
   bool option_unspecified_p (option_id opt_id) const
   {
-    return get_current_override (opt_id) == DK_UNSPECIFIED;
+    return get_current_override (opt_id) == kind::unspecified;
   }
 
-  diagnostic_t get_current_override (option_id opt_id) const
+  enum kind get_current_override (option_id opt_id) const
   {
     gcc_assert (opt_id.m_idx < m_n_opts);
     return m_classify_diagnostic[opt_id.m_idx];
   }
 
-  diagnostic_t
+  enum kind
   classify_diagnostic (const context *context,
 		       option_id opt_id,
-		       diagnostic_t new_kind,
+		       enum kind new_kind,
 		       location_t where);
 
-  diagnostic_t
+  enum kind
   update_effective_level_from_pragmas (diagnostic_info *diagnostic) const;
 
   int pch_save (FILE *);
@@ -73,12 +73,12 @@ private:
   {
     location_t location;
 
-    /* For DK_POP, this is the index of the corresponding push (as stored
+    /* For kind::pop, this is the index of the corresponding push (as stored
        in m_push_list).
        Otherwise, this is an option index.  */
     int option;
 
-    diagnostic_t kind;
+    enum kind kind;
   };
 
   int m_n_opts;
@@ -86,10 +86,10 @@ private:
   /* For each option index that can be passed to warning() et al
      (OPT_* from options.h when using this code with the core GCC
      options), this array may contain a new kind that the diagnostic
-     should be changed to before reporting, or DK_UNSPECIFIED to leave
-     it as the reported kind, or DK_IGNORED to not report it at
+     should be changed to before reporting, or kind::unspecified to leave
+     it as the reported kind, or kind::ignored to not report it at
      all.  */
-  diagnostic_t *m_classify_diagnostic;
+  enum kind *m_classify_diagnostic;
 
   /* History of all changes to the classifications above.  This list
      is stored in location-order, so we can search it, either
diff --git a/gcc/diagnostics/output-spec.h b/gcc/diagnostics/output-spec.h
index dd9541f99e47..059346a25d20 100644
--- a/gcc/diagnostics/output-spec.h
+++ b/gcc/diagnostics/output-spec.h
@@ -103,7 +103,7 @@ public:
   {
     m_dc.begin_group ();
     rich_location richloc (m_control_location_mgr, m_loc);
-    m_dc.diagnostic_impl (&richloc, nullptr, -1, gmsgid, ap, DK_ERROR);
+    m_dc.diagnostic_impl (&richloc, nullptr, -1, gmsgid, ap, kind::error);
     m_dc.end_group ();
   }
 
diff --git a/gcc/diagnostics/paths-output.cc b/gcc/diagnostics/paths-output.cc
index 0349f3d943d6..c132d6735042 100644
--- a/gcc/diagnostics/paths-output.cc
+++ b/gcc/diagnostics/paths-output.cc
@@ -638,7 +638,7 @@ struct event_range
 
     /* Call diagnostic_show_locus to show the events using labels.  */
     diagnostic_show_locus (&dc, text_output.get_source_printing_options (),
-			   &m_richloc, DK_DIAGNOSTIC_PATH, &pp,
+			   &m_richloc, diagnostics::kind::path, &pp,
 			   effect_info);
 
     /* If we have a macro expansion, show the expansion to the user.  */
@@ -702,7 +702,7 @@ struct event_range
     /* Call diagnostic_show_locus_as_html to show the source,
        showing events using labels.  */
     diagnostic_show_locus_as_html (&dc, dc.m_source_printing,
-				   &m_richloc, DK_DIAGNOSTIC_PATH, xp,
+				   &m_richloc, diagnostics::kind::path, xp,
 				   effect_info, event_label_writer);
 
     // TODO: show macro expansions
diff --git a/gcc/diagnostics/sarif-sink.cc b/gcc/diagnostics/sarif-sink.cc
index a18320322d0f..b0de5396f882 100644
--- a/gcc/diagnostics/sarif-sink.cc
+++ b/gcc/diagnostics/sarif-sink.cc
@@ -452,7 +452,7 @@ public:
 
   void
   on_nested_diagnostic (const diagnostic_info &diagnostic,
-			diagnostic_t orig_diag_kind,
+			enum kind orig_diag_kind,
 			sarif_builder &builder);
   void on_diagram (const diagram &d,
 		   sarif_builder &builder);
@@ -775,7 +775,7 @@ public:
   set_main_input_filename (const char *name);
 
   void on_report_diagnostic (const diagnostic_info &diagnostic,
-			     diagnostic_t orig_diag_kind,
+			     enum kind orig_diag_kind,
 			     sarif_sink_buffer *buffer);
   void emit_diagram (const diagram &d);
   void end_group ();
@@ -854,7 +854,7 @@ private:
 
   std::unique_ptr<sarif_result>
   make_result_object (const diagnostic_info &diagnostic,
-		      diagnostic_t orig_diag_kind,
+		      enum kind orig_diag_kind,
 		      unsigned idx_within_parent);
   void
   add_any_include_chain (sarif_location_manager &loc_mgr,
@@ -918,7 +918,7 @@ private:
   make_tool_component_reference_object_for_cwe () const;
   std::unique_ptr<sarif_reporting_descriptor>
   make_reporting_descriptor_object_for_warning (const diagnostic_info &diagnostic,
-						diagnostic_t orig_diag_kind,
+						enum kind orig_diag_kind,
 						const char *option_text);
   std::unique_ptr<sarif_reporting_descriptor>
   make_reporting_descriptor_object_for_cwe_id (int cwe_id) const;
@@ -1307,7 +1307,7 @@ sarif_location_manager::process_worklist_item (sarif_builder &builder,
 
 void
 sarif_result::on_nested_diagnostic (const diagnostic_info &diagnostic,
-				    diagnostic_t /*orig_diag_kind*/,
+				    enum kind /*orig_diag_kind*/,
 				    sarif_builder &builder)
 {
   /* We don't yet generate meaningful logical locations for notes;
@@ -1840,12 +1840,12 @@ sarif_builder::set_main_input_filename (const char *name)
 
 void
 sarif_builder::on_report_diagnostic (const diagnostic_info &diagnostic,
-				     diagnostic_t orig_diag_kind,
+				     enum kind orig_diag_kind,
 				     sarif_sink_buffer *buffer)
 {
   pp_output_formatted_text (m_printer, m_context.get_urlifier ());
 
-  if (diagnostic.m_kind == DK_ICE || diagnostic.m_kind == DK_ICE_NOBT)
+  if (diagnostic.m_kind == kind::ice || diagnostic.m_kind == kind::ice_nobt)
     {
       std::unique_ptr<json::object> stack = make_stack_from_backtrace ();
       m_invocation_obj->add_notification_for_ice (diagnostic, *this,
@@ -1949,16 +1949,16 @@ sarif_builder::flush_to_file (FILE *outf)
    Return nullptr if there isn't one.  */
 
 static const char *
-maybe_get_sarif_level (diagnostic_t diag_kind)
+maybe_get_sarif_level (enum kind diag_kind)
 {
   switch (diag_kind)
     {
-    case DK_WARNING:
+    case kind::warning:
       return "warning";
-    case DK_ERROR:
+    case kind::error:
       return "error";
-    case DK_NOTE:
-    case DK_ANACHRONISM:
+    case kind::note:
+    case kind::anachronism:
       return "note";
     default:
       return nullptr;
@@ -1970,10 +1970,10 @@ maybe_get_sarif_level (diagnostic_t diag_kind)
    have anything better to use.  */
 
 static char *
-make_rule_id_for_diagnostic_kind (diagnostic_t diag_kind)
+make_rule_id_for_diagnostic_kind (enum kind diag_kind)
 {
   /* Lose the trailing ": ".  */
-  const char *kind_text = get_diagnostic_kind_text (diag_kind);
+  const char *kind_text = get_text_for_kind (diag_kind);
   size_t len = strlen (kind_text);
   gcc_assert (len > 2);
   gcc_assert (kind_text[len - 2] == ':');
@@ -1987,7 +1987,7 @@ make_rule_id_for_diagnostic_kind (diagnostic_t diag_kind)
 
 std::unique_ptr<sarif_result>
 sarif_builder::make_result_object (const diagnostic_info &diagnostic,
-				   diagnostic_t orig_diag_kind,
+				   enum kind orig_diag_kind,
 				   unsigned idx_within_parent)
 {
   auto result_obj = std::make_unique<sarif_result> (idx_within_parent);
@@ -2106,7 +2106,7 @@ sarif_builder::make_result_object (const diagnostic_info &diagnostic,
 std::unique_ptr<sarif_reporting_descriptor>
 sarif_builder::
 make_reporting_descriptor_object_for_warning (const diagnostic_info &diagnostic,
-					      diagnostic_t /*orig_diag_kind*/,
+					      enum kind /*orig_diag_kind*/,
 					      const char *option_text)
 {
   auto reporting_desc = std::make_unique<sarif_reporting_descriptor> ();
@@ -2281,7 +2281,7 @@ sarif_builder::make_location_object (sarif_location_manager *loc_mgr,
       dc.set_escape_format (m_escape_format);
       text_sink text_output (dc);
       source_policy.print (*text_output.get_printer (),
-			   my_rich_loc, DK_ERROR, nullptr);
+			   my_rich_loc, kind::error, nullptr);
 
       const char *buf = pp_formatted_text (text_output.get_printer ());
       std::unique_ptr<sarif_multiformat_message_string> result
@@ -3915,7 +3915,7 @@ public:
   }
   void
   on_report_diagnostic (const diagnostic_info &diagnostic,
-			diagnostic_t orig_diag_kind) final override
+			enum kind orig_diag_kind) final override
   {
     m_builder.on_report_diagnostic (diagnostic, orig_diag_kind, m_buffer);
   }
@@ -4189,7 +4189,7 @@ output_file::try_to_open (context &dc,
     {
       rich_location richloc (line_maps, UNKNOWN_LOCATION);
       dc.emit_diagnostic_with_group
-	(DK_ERROR, richloc, nullptr, 0,
+	(kind::error, richloc, nullptr, 0,
 	 "unable to determine filename for SARIF output");
       return output_file ();
     }
@@ -4202,7 +4202,7 @@ output_file::try_to_open (context &dc,
     {
       rich_location richloc (line_maps, UNKNOWN_LOCATION);
       dc.emit_diagnostic_with_group
-	(DK_ERROR, richloc, nullptr, 0,
+	(kind::error, richloc, nullptr, 0,
 	 "unable to open %qs for diagnostic output: %m",
 	 filename.get ());
       return output_file ();
@@ -4583,7 +4583,7 @@ test_simple_log (const sarif_generation_options &sarif_gen_opts)
   test_sarif_diagnostic_context dc ("MAIN_INPUT_FILENAME", sarif_gen_opts);
 
   rich_location richloc (line_table, UNKNOWN_LOCATION);
-  dc.report (DK_ERROR, richloc, nullptr, 0, "this is a test: %i", 42);
+  dc.report (kind::error, richloc, nullptr, 0, "this is a test: %i", 42);
 
   auto log_ptr = dc.flush_to_object ();
 
@@ -4720,7 +4720,7 @@ test_simple_log_2 (const sarif_generation_options &sarif_gen_opts,
 		     linemap_position_for_column (line_table, 8));
 
   rich_location richloc (line_table, typo_loc);
-  dc.report (DK_ERROR, richloc, nullptr, 0,
+  dc.report (kind::error, richloc, nullptr, 0,
 	     "did you misspell %qs again?",
 	     "unsigned");
 
@@ -4848,7 +4848,7 @@ test_message_with_embedded_link (const sarif_generation_options &sarif_gen_opts)
   {
     test_sarif_diagnostic_context dc ("test.c", sarif_gen_opts);
     rich_location richloc (line_table, UNKNOWN_LOCATION);
-    dc.report (DK_ERROR, richloc, nullptr, 0,
+    dc.report (kind::error, richloc, nullptr, 0,
 	       "before %{text%} after",
 	       "http://example.com");
     std::unique_ptr<sarif_log> log = dc.flush_to_object ();
@@ -4871,7 +4871,7 @@ test_message_with_embedded_link (const sarif_generation_options &sarif_gen_opts)
 #  pragma GCC diagnostic push
 #  pragma GCC diagnostic ignored "-Wformat-diag"
 #endif
-    dc.report (DK_ERROR, richloc, nullptr, 0,
+    dc.report (kind::error, richloc, nullptr, 0,
 	       "Prohibited term used in %{para[0]\\spans[2]%}.",
 	       "1");
 #if __GNUC__ >= 10
@@ -4905,7 +4905,7 @@ test_message_with_embedded_link (const sarif_generation_options &sarif_gen_opts)
     test_sarif_diagnostic_context dc ("test.c", sarif_gen_opts);
     dc.push_owned_urlifier (std::make_unique<test_urlifier> ());
     rich_location richloc (line_table, UNKNOWN_LOCATION);
-    dc.report (DK_ERROR, richloc, nullptr, 0,
+    dc.report (kind::error, richloc, nullptr, 0,
 	       "foo %<-foption%> %<unrecognized%> bar");
     std::unique_ptr<sarif_log> log = dc.flush_to_object ();
 
@@ -4926,7 +4926,7 @@ test_message_with_braces (const sarif_generation_options &sarif_gen_opts)
   {
     test_sarif_diagnostic_context dc ("test.c", sarif_gen_opts);
     rich_location richloc (line_table, UNKNOWN_LOCATION);
-    dc.report (DK_ERROR, richloc, nullptr, 0,
+    dc.report (kind::error, richloc, nullptr, 0,
 	       "open brace: %qs close brace: %qs",
 	       "{", "}");
     std::unique_ptr<sarif_log> log = dc.flush_to_object ();
@@ -4948,21 +4948,21 @@ test_buffering (const sarif_generation_options &sarif_gen_opts)
 
   rich_location rich_loc (line_table, UNKNOWN_LOCATION);
 
-  ASSERT_EQ (dc.diagnostic_count (DK_ERROR), 0);
-  ASSERT_EQ (buf_a.diagnostic_count (DK_ERROR), 0);
-  ASSERT_EQ (buf_b.diagnostic_count (DK_ERROR), 0);
+  ASSERT_EQ (dc.diagnostic_count (kind::error), 0);
+  ASSERT_EQ (buf_a.diagnostic_count (kind::error), 0);
+  ASSERT_EQ (buf_b.diagnostic_count (kind::error), 0);
   ASSERT_EQ (dc.num_results (), 0);
   ASSERT_TRUE (buf_a.empty_p ());
   ASSERT_TRUE (buf_b.empty_p ());
 
   /* Unbuffered diagnostic.  */
   {
-    dc.report (DK_ERROR, rich_loc, nullptr, 0,
+    dc.report (kind::error, rich_loc, nullptr, 0,
 	       "message 1");
 
-    ASSERT_EQ (dc.diagnostic_count (DK_ERROR), 1);
-    ASSERT_EQ (buf_a.diagnostic_count (DK_ERROR), 0);
-    ASSERT_EQ (buf_b.diagnostic_count (DK_ERROR), 0);
+    ASSERT_EQ (dc.diagnostic_count (kind::error), 1);
+    ASSERT_EQ (buf_a.diagnostic_count (kind::error), 0);
+    ASSERT_EQ (buf_b.diagnostic_count (kind::error), 0);
     ASSERT_EQ (dc.num_results (), 1);
     sarif_result &result_obj = dc.get_result (0);
     auto message_obj = get_message_from_result (result_obj);
@@ -4975,11 +4975,11 @@ test_buffering (const sarif_generation_options &sarif_gen_opts)
   /* Buffer diagnostic into buffer A.  */
   {
     dc.set_diagnostic_buffer (&buf_a);
-    dc.report (DK_ERROR, rich_loc, nullptr, 0,
+    dc.report (kind::error, rich_loc, nullptr, 0,
 	       "message in buffer a");
-    ASSERT_EQ (dc.diagnostic_count (DK_ERROR), 1);
-    ASSERT_EQ (buf_a.diagnostic_count (DK_ERROR), 1);
-    ASSERT_EQ (buf_b.diagnostic_count (DK_ERROR), 0);
+    ASSERT_EQ (dc.diagnostic_count (kind::error), 1);
+    ASSERT_EQ (buf_a.diagnostic_count (kind::error), 1);
+    ASSERT_EQ (buf_b.diagnostic_count (kind::error), 0);
     ASSERT_EQ (dc.num_results (), 1);
     ASSERT_FALSE (buf_a.empty_p ());
     ASSERT_TRUE (buf_b.empty_p ());
@@ -4988,11 +4988,11 @@ test_buffering (const sarif_generation_options &sarif_gen_opts)
   /* Buffer diagnostic into buffer B.  */
   {
     dc.set_diagnostic_buffer (&buf_b);
-    dc.report (DK_ERROR, rich_loc, nullptr, 0,
+    dc.report (kind::error, rich_loc, nullptr, 0,
 	       "message in buffer b");
-    ASSERT_EQ (dc.diagnostic_count (DK_ERROR), 1);
-    ASSERT_EQ (buf_a.diagnostic_count (DK_ERROR), 1);
-    ASSERT_EQ (buf_b.diagnostic_count (DK_ERROR), 1);
+    ASSERT_EQ (dc.diagnostic_count (kind::error), 1);
+    ASSERT_EQ (buf_a.diagnostic_count (kind::error), 1);
+    ASSERT_EQ (buf_b.diagnostic_count (kind::error), 1);
     ASSERT_EQ (dc.num_results (), 1);
     ASSERT_FALSE (buf_a.empty_p ());
     ASSERT_FALSE (buf_b.empty_p ());
@@ -5001,9 +5001,9 @@ test_buffering (const sarif_generation_options &sarif_gen_opts)
   /* Flush buffer B to dc.  */
   {
     dc.flush_diagnostic_buffer (buf_b);
-    ASSERT_EQ (dc.diagnostic_count (DK_ERROR), 2);
-    ASSERT_EQ (buf_a.diagnostic_count (DK_ERROR), 1);
-    ASSERT_EQ (buf_b.diagnostic_count (DK_ERROR), 0);
+    ASSERT_EQ (dc.diagnostic_count (kind::error), 2);
+    ASSERT_EQ (buf_a.diagnostic_count (kind::error), 1);
+    ASSERT_EQ (buf_b.diagnostic_count (kind::error), 0);
     ASSERT_EQ (dc.num_results (), 2);
     sarif_result &result_1_obj = dc.get_result (1);
     auto message_1_obj = get_message_from_result (result_1_obj);
@@ -5016,9 +5016,9 @@ test_buffering (const sarif_generation_options &sarif_gen_opts)
   /* Clear buffer A.  */
   {
     dc.clear_diagnostic_buffer (buf_a);
-    ASSERT_EQ (dc.diagnostic_count (DK_ERROR), 2);
-    ASSERT_EQ (buf_a.diagnostic_count (DK_ERROR), 0);
-    ASSERT_EQ (buf_b.diagnostic_count (DK_ERROR), 0);
+    ASSERT_EQ (dc.diagnostic_count (kind::error), 2);
+    ASSERT_EQ (buf_a.diagnostic_count (kind::error), 0);
+    ASSERT_EQ (buf_b.diagnostic_count (kind::error), 0);
     ASSERT_EQ (dc.num_results (), 2);
     ASSERT_TRUE (buf_a.empty_p ());
     ASSERT_TRUE (buf_b.empty_p ());
diff --git a/gcc/diagnostics/selftest-context.cc b/gcc/diagnostics/selftest-context.cc
index 880c169fa861..4f215c222e25 100644
--- a/gcc/diagnostics/selftest-context.cc
+++ b/gcc/diagnostics/selftest-context.cc
@@ -68,7 +68,7 @@ start_span_cb (const location_print_policy &loc_policy,
 }
 
 bool
-test_context::report (diagnostic_t kind,
+test_context::report (enum kind kind,
 		      rich_location &richloc,
 		      const metadata *metadata_,
 		      option_id opt_id,
@@ -92,7 +92,7 @@ test_context::test_show_locus (rich_location &richloc)
   pretty_printer *pp = get_reference_printer ();
   gcc_assert (pp);
   source_print_policy source_policy (*this);
-  source_policy.print (*pp, richloc, DK_ERROR, nullptr);
+  source_policy.print (*pp, richloc, kind::error, nullptr);
   return pp_formatted_text (pp);
 }
 
diff --git a/gcc/diagnostics/selftest-context.h b/gcc/diagnostics/selftest-context.h
index b0296d55f0d9..009b32b7c4d2 100644
--- a/gcc/diagnostics/selftest-context.h
+++ b/gcc/diagnostics/selftest-context.h
@@ -48,7 +48,7 @@ class test_context : public context
      should only be called on a context that uses a non-standard formatter
      that e.g. gathers the results in memory, rather than emits to stderr.  */
   bool
-  report (diagnostic_t kind,
+  report (enum kind kind,
 	  rich_location &richloc,
 	  const metadata *,
 	  option_id opt_id,
diff --git a/gcc/diagnostics/sink.h b/gcc/diagnostics/sink.h
index e8b541808063..04de99a06df1 100644
--- a/gcc/diagnostics/sink.h
+++ b/gcc/diagnostics/sink.h
@@ -59,7 +59,7 @@ public:
   /* Vfunc with responsibility for phase 3 of formatting the message
      and "printing" the result.  */
   virtual void on_report_diagnostic (const diagnostic_info &,
-				     diagnostic_t orig_diag_kind) = 0;
+				     enum kind orig_diag_kind) = 0;
 
   virtual void on_report_verbatim (text_info &);
 
diff --git a/gcc/diagnostics/source-printing.cc b/gcc/diagnostics/source-printing.cc
index d5d374115daa..f47b1b9866b1 100644
--- a/gcc/diagnostics/source-printing.cc
+++ b/gcc/diagnostics/source-printing.cc
@@ -96,7 +96,7 @@ class colorizer
  public:
   colorizer (pretty_printer &pp,
 	     const rich_location &richloc,
-	     diagnostic_t diagnostic_kind);
+	     enum diagnostics::kind diagnostic_kind);
   ~colorizer ();
 
   void set_range (int range_idx)
@@ -116,7 +116,7 @@ class colorizer
        two colors for the secondary locations.
        But if we're printing a run of events in a diagnostic path, that
        makes no sense, so print all of them with the same colorization.  */
-    if (m_diagnostic_kind == DK_DIAGNOSTIC_PATH)
+    if (m_diagnostic_kind == diagnostics::kind::path)
       set_state (0);
     else
       set_state (range_idx);
@@ -141,7 +141,7 @@ class colorizer
 
   pretty_printer &m_pp;
   const rich_location &m_richloc;
-  diagnostic_t m_diagnostic_kind;
+  enum diagnostics::kind m_diagnostic_kind;
   int m_current_state;
   const char *m_range1;
   const char *m_range2;
@@ -947,7 +947,7 @@ private:
 
 colorizer::colorizer (pretty_printer &pp,
 		      const rich_location &richloc,
-		      diagnostic_t diagnostic_kind) :
+		      enum diagnostics::kind diagnostic_kind) :
   m_pp (pp),
   m_richloc (richloc),
   m_diagnostic_kind (diagnostic_kind),
@@ -1025,7 +1025,7 @@ colorizer::begin_state (int state)
       pp_string
 	(&m_pp,
 	 colorize_start (pp_show_color (&m_pp),
-			 diagnostic_get_color_for_kind (m_diagnostic_kind)));
+			 get_color_for_kind (m_diagnostic_kind)));
       break;
 
     case 1:
@@ -3851,7 +3851,7 @@ namespace diagnostics {
 void
 context::maybe_show_locus (const rich_location &richloc,
 			   const source_printing_options &opts,
-			   diagnostic_t diagnostic_kind,
+			   enum kind diagnostic_kind,
 			   pretty_printer &pp,
 			   source_effect_info *effects)
 {
@@ -3884,7 +3884,7 @@ context::maybe_show_locus (const rich_location &richloc,
 void
 context::maybe_show_locus_as_html (const rich_location &richloc,
 				   const source_printing_options &opts,
-				   diagnostic_t diagnostic_kind,
+				   enum kind diagnostic_kind,
 				   xml::printer &xp,
 				   source_effect_info *effects,
 				   html_label_writer *label_writer)
@@ -3945,14 +3945,14 @@ source_print_policy::source_print_policy (const context &dc,
 void
 source_print_policy::print (pretty_printer &pp,
 			    const rich_location &richloc,
-			    diagnostic_t diagnostic_kind,
+			    enum kind diagnostic_kind,
 			    source_effect_info *effects) const
 {
   layout layout (*this, richloc, effects);
   colorizer col (pp, richloc, diagnostic_kind);
   to_text sink (pp, col);
   layout_printer<to_text> lp (sink, layout,
-			      diagnostic_kind == DK_DIAGNOSTIC_PATH);
+			      diagnostic_kind == diagnostics::kind::path);
   lp.print (*this);
 }
 
@@ -3962,14 +3962,14 @@ source_print_policy::print (pretty_printer &pp,
 void
 source_print_policy::print_as_html (xml::printer &xp,
 				    const rich_location &richloc,
-				    diagnostic_t diagnostic_kind,
+				    enum kind diagnostic_kind,
 				    source_effect_info *effects,
 				    html_label_writer *label_writer) const
 {
   layout layout (*this, richloc, effects);
   to_html sink (xp, &richloc, label_writer);
   layout_printer<to_html> lp (sink, layout,
-			      diagnostic_kind == DK_DIAGNOSTIC_PATH);
+			      diagnostic_kind == diagnostics::kind::path);
   xml::auto_check_tag_nesting sentinel (xp);
   lp.print (*this);
 }
@@ -4043,7 +4043,7 @@ using temp_source_file = ::selftest::temp_source_file;
 
 static std::unique_ptr<xml::node>
 make_element_for_locus (const rich_location &rich_loc,
-			diagnostic_t kind,
+			enum kind kind,
 			diagnostics::context &dc)
 {
   dc.m_last_location = UNKNOWN_LOCATION;
@@ -4064,7 +4064,7 @@ make_element_for_locus (const rich_location &rich_loc,
 
 static label_text
 make_raw_html_for_locus (const rich_location &rich_loc,
-			 diagnostic_t kind,
+			 enum kind kind,
 			 diagnostics::context &dc)
 {
   auto node = make_element_for_locus (rich_loc, kind, dc);
@@ -4292,7 +4292,7 @@ test_layout_x_offset_display_utf8 (const line_table_case &case_)
 							emoji_col));
     layout test_layout (policy, richloc, nullptr);
     colorizer col (*dc.get_reference_printer (),
-		   richloc, DK_ERROR);
+		   richloc, diagnostics::kind::error);
     diagnostics::to_text sink (*dc.get_reference_printer (), col);
     layout_printer<diagnostics::to_text> lp (sink, test_layout, false);
     lp.print (policy);
@@ -4322,7 +4322,7 @@ test_layout_x_offset_display_utf8 (const line_table_case &case_)
 							emoji_col + 2));
     layout test_layout (dc, richloc, nullptr);
     colorizer col (*dc.get_reference_printer (),
-		   richloc, DK_ERROR);
+		   richloc, diagnostics::kind::error);
     diagnostics::to_text sink (*dc.get_reference_printer (), col);
     layout_printer<diagnostics::to_text> lp (sink, test_layout, false);
     lp.print (policy);
@@ -4406,7 +4406,7 @@ test_layout_x_offset_display_tab (const line_table_case &case_)
       diagnostics::source_print_policy policy (dc);
       layout test_layout (policy, richloc, nullptr);
       colorizer col (*dc.get_reference_printer (),
-		     richloc, DK_ERROR);
+		     richloc, diagnostics::kind::error);
       diagnostics::to_text sink (*dc.get_reference_printer (), col);
       layout_printer<diagnostics::to_text> lp (sink, test_layout, false);
       lp.print (policy);
@@ -4434,7 +4434,7 @@ test_layout_x_offset_display_tab (const line_table_case &case_)
       diagnostics::source_print_policy policy (dc);
       layout test_layout (policy, richloc, nullptr);
       colorizer col (*dc.get_reference_printer (),
-		     richloc, DK_ERROR);
+		     richloc, diagnostics::kind::error);
       diagnostics::to_text sink (*dc.get_reference_printer (), col);
       layout_printer<diagnostics::to_text> lp (sink, test_layout, false);
       lp.print (policy);
@@ -4520,7 +4520,7 @@ test_one_liner_caret_and_range ()
 
   {
     test_context dc;
-    auto out = make_raw_html_for_locus (richloc, DK_ERROR, dc);
+    auto out = make_raw_html_for_locus (richloc, diagnostics::kind::error, dc);
      ASSERT_STREQ
        ("<table class=\"locus\">\n"
 	"  <tbody class=\"line-span\">\n"
@@ -4533,7 +4533,7 @@ test_one_liner_caret_and_range ()
   {
     test_context dc;
     dc.m_source_printing.show_line_numbers_p = true;
-    auto out = make_raw_html_for_locus (richloc, DK_ERROR, dc);
+    auto out = make_raw_html_for_locus (richloc, diagnostics::kind::error, dc);
      ASSERT_STREQ
        ("<table class=\"locus\">\n"
 	"  <tbody class=\"line-span\">\n"
@@ -4964,7 +4964,8 @@ test_one_liner_labels ()
     {
       test_context dc;
       dc.m_source_printing.show_line_numbers_p = true;
-      auto out = make_raw_html_for_locus (richloc, DK_ERROR, dc);
+      auto out
+	= make_raw_html_for_locus (richloc, diagnostics::kind::error, dc);
       ASSERT_STREQ
 	("<table class=\"locus\">\n"
 	 "  <tbody class=\"line-span\">\n"
diff --git a/gcc/diagnostics/text-sink.cc b/gcc/diagnostics/text-sink.cc
index 8c970926f850..9974fda4c898 100644
--- a/gcc/diagnostics/text-sink.cc
+++ b/gcc/diagnostics/text-sink.cc
@@ -132,7 +132,7 @@ text_sink_buffer::flush ()
 text_sink::~text_sink ()
 {
   /* Some of the errors may actually have been warnings.  */
-  if (m_context.diagnostic_count (DK_WERROR))
+  if (m_context.diagnostic_count (kind::werror))
     {
       pretty_printer *pp = get_printer ();
       /* -Werror was given.  */
@@ -201,7 +201,7 @@ text_sink::make_per_sink_buffer ()
 
 void
 text_sink::on_report_diagnostic (const diagnostic_info &diagnostic,
-				 diagnostic_t orig_diag_kind)
+				 enum kind orig_diag_kind)
 {
   pretty_printer *pp = get_printer ();
 
@@ -291,13 +291,13 @@ after_diagnostic (const diagnostic_info &diagnostic)
 char *
 text_sink::build_prefix (const diagnostic_info &diagnostic) const
 {
-  gcc_assert (diagnostic.m_kind < DK_LAST_DIAGNOSTIC_KIND);
+  gcc_assert (diagnostic.m_kind < kind::last_diagnostic_kind);
 
-  const char *text = _(get_diagnostic_kind_text (diagnostic.m_kind));
+  const char *text = _(get_text_for_kind (diagnostic.m_kind));
   const char *text_cs = "", *text_ce = "";
   pretty_printer *pp = get_printer ();
 
-  if (const char *color_name = diagnostic_get_color_for_kind (diagnostic.m_kind))
+  if (const char *color_name = get_color_for_kind (diagnostic.m_kind))
     {
       text_cs = colorize_start (pp_show_color (pp), color_name);
       text_ce = colorize_stop (pp_show_color (pp));
@@ -310,7 +310,7 @@ text_sink::build_prefix (const diagnostic_info &diagnostic) const
 
       /* Reduce verbosity of nested diagnostics by not printing "note: "
 	 all the time.  */
-      if (diagnostic.m_kind == DK_NOTE)
+      if (diagnostic.m_kind == kind::note)
 	return indent_prefix;
 
       char *result = build_message_string ("%s%s%s%s", indent_prefix,
@@ -416,7 +416,7 @@ text_sink::append_note (location_t location,
   rich_location richloc (line_table, location);
 
   va_start (ap, gmsgid);
-  diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_NOTE);
+  diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, kind::note);
   if (dc->m_inhibit_notes_p)
     {
       va_end (ap);
@@ -431,7 +431,7 @@ text_sink::append_note (location_t location,
   pp_set_prefix (pp, saved_prefix);
   pp_newline (pp);
   diagnostic_show_locus (dc, get_source_printing_options (),
-			 &richloc, DK_NOTE, pp);
+			 &richloc, kind::note, pp);
   va_end (ap);
 }
 
@@ -478,7 +478,7 @@ text_sink::print_any_cwe (const diagnostic_info &diagnostic)
       pretty_printer * const pp = get_printer ();
       char *saved_prefix = pp_take_prefix (pp);
       pp_string (pp, " [");
-      const char *kind_color = diagnostic_get_color_for_kind (diagnostic.m_kind);
+      const char *kind_color = get_color_for_kind (diagnostic.m_kind);
       pp_string (pp, colorize_start (pp_show_color (pp), kind_color));
       if (pp->supports_urls_p ())
 	{
@@ -516,8 +516,7 @@ text_sink::print_any_rules (const diagnostic_info &diagnostic)
 	  pretty_printer * const pp = get_printer ();
 	  char *saved_prefix = pp_take_prefix (pp);
 	  pp_string (pp, " [");
-	  const char *kind_color
-	    = diagnostic_get_color_for_kind (diagnostic.m_kind);
+	  const char *kind_color = get_color_for_kind (diagnostic.m_kind);
 	  pp_string (pp, colorize_start (pp_show_color (pp), kind_color));
 	  char *url = nullptr;
 	  if (pp->supports_urls_p ())
@@ -544,7 +543,7 @@ text_sink::print_any_rules (const diagnostic_info &diagnostic)
 
 void
 text_sink::print_option_information (const diagnostic_info &diagnostic,
-				     diagnostic_t orig_diag_kind)
+				     enum kind orig_diag_kind)
 {
   if (char *option_text
       = m_context.make_option_name (diagnostic.m_option_id,
@@ -555,7 +554,7 @@ text_sink::print_option_information (const diagnostic_info &diagnostic,
       if (pp->supports_urls_p ())
 	option_url = m_context.make_option_url (diagnostic.m_option_id);
       pp_string (pp, " [");
-      const char *kind_color = diagnostic_get_color_for_kind (diagnostic.m_kind);
+      const char *kind_color = get_color_for_kind (diagnostic.m_kind);
       pp_string (pp, colorize_start (pp_show_color (pp), kind_color));
       if (option_url)
 	pp_begin_url (pp, option_url);
@@ -709,7 +708,7 @@ default_text_starter (text_sink &text_output,
 void
 default_text_finalizer (text_sink &text_output,
 			const diagnostic_info *diagnostic,
-			diagnostic_t)
+			enum kind)
 {
   pretty_printer *const pp = text_output.get_printer ();
   char *saved_prefix = pp_take_prefix (pp);
diff --git a/gcc/diagnostics/text-sink.h b/gcc/diagnostics/text-sink.h
index f008cb33601d..9ec36f1b3253 100644
--- a/gcc/diagnostics/text-sink.h
+++ b/gcc/diagnostics/text-sink.h
@@ -60,7 +60,7 @@ public:
   void on_begin_group () override {}
   void on_end_group () override {}
   void on_report_diagnostic (const diagnostic_info &,
-			     diagnostic_t orig_diag_kind) override;
+			     enum kind orig_diag_kind) override;
   void on_report_verbatim (text_info &) final override;
   void on_diagram (const diagram &d) override;
   void after_diagnostic (const diagnostic_info &) override;
@@ -130,7 +130,7 @@ protected:
   void print_any_cwe (const diagnostic_info &diagnostic);
   void print_any_rules (const diagnostic_info &diagnostic);
   void print_option_information (const diagnostic_info &diagnostic,
-				 diagnostic_t orig_diag_kind);
+				 enum kind orig_diag_kind);
 
   bool includes_seen_p (const line_map_ordinary *map);
 
diff --git a/gcc/fortran/cpp.cc b/gcc/fortran/cpp.cc
index 3e540072a5de..01113589fe7b 100644
--- a/gcc/fortran/cpp.cc
+++ b/gcc/fortran/cpp.cc
@@ -1089,7 +1089,7 @@ cb_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED,
 		   const char *msg, va_list *ap)
 {
   diagnostic_info diagnostic;
-  diagnostic_t dlevel;
+  enum diagnostics::kind dlevel;
   bool save_warn_system_headers = global_dc->m_warn_system_headers;
   bool ret;
 
@@ -1099,22 +1099,22 @@ cb_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED,
       global_dc->m_warn_system_headers = 1;
       /* Fall through.  */
     case CPP_DL_WARNING:
-      dlevel = DK_WARNING;
+      dlevel = diagnostics::kind::warning;
       break;
     case CPP_DL_PEDWARN:
-      dlevel = DK_PEDWARN;
+      dlevel = diagnostics::kind::pedwarn;
       break;
     case CPP_DL_ERROR:
-      dlevel = DK_ERROR;
+      dlevel = diagnostics::kind::error;
       break;
     case CPP_DL_ICE:
-      dlevel = DK_ICE;
+      dlevel = diagnostics::kind::ice;
       break;
     case CPP_DL_NOTE:
-      dlevel = DK_NOTE;
+      dlevel = diagnostics::kind::note;
       break;
     case CPP_DL_FATAL:
-      dlevel = DK_FATAL;
+      dlevel = diagnostics::kind::fatal;
       break;
     default:
       gcc_unreachable ();
diff --git a/gcc/fortran/error.cc b/gcc/fortran/error.cc
index a9e99b4c3da0..8d913aa89ef6 100644
--- a/gcc/fortran/error.cc
+++ b/gcc/fortran/error.cc
@@ -272,7 +272,7 @@ gfc_warning (int opt, const char *gmsgid, va_list ap)
     global_dc->set_diagnostic_buffer (pp_warning_buffer);
 
   diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc,
-		       DK_WARNING);
+		       diagnostics::kind::warning);
   diagnostic.m_option_id = opt;
   bool ret = gfc_report_diagnostic (&diagnostic);
 
@@ -441,7 +441,7 @@ gfc_format_decoder (pretty_printer *pp, text_info *text, const char *spec,
 	const char *color
 	  = (loc_num
 	     ? "range1"
-	     : diagnostic_get_color_for_kind (curr_diagnostic->m_kind));
+	     : diagnostics::get_color_for_kind (curr_diagnostic->m_kind));
 	pp_string (pp, colorize_start (pp_show_color (pp), color));
 	pp_string (pp, result[loc_num]);
 	pp_string (pp, colorize_stop (pp_show_color (pp)));
@@ -475,15 +475,16 @@ gfc_diagnostic_build_kind_prefix (diagnostics::context *context,
 #undef DEFINE_DIAGNOSTIC_KIND
     NULL
   };
-  gcc_assert (diagnostic->m_kind < DK_LAST_DIAGNOSTIC_KIND);
-  const char *text = _(diagnostic_kind_text[diagnostic->m_kind]);
+  const int diag_kind_idx = static_cast<int> (diagnostic->m_kind);
+  gcc_assert (diagnostic->m_kind < diagnostics::kind::last_diagnostic_kind);
+  const char *text = _(diagnostic_kind_text[diag_kind_idx]);
   const char *text_cs = "", *text_ce = "";
   pretty_printer *const pp = context->get_reference_printer ();
 
-  if (diagnostic_kind_color[diagnostic->m_kind])
+if (diagnostic_kind_color[diag_kind_idx])
     {
       text_cs = colorize_start (pp_show_color (pp),
-				diagnostic_kind_color[diagnostic->m_kind]);
+				diagnostic_kind_color[diag_kind_idx]);
       text_ce = colorize_stop (pp_show_color (pp));
     }
   return build_message_string ("%s%s:%s ", text_cs, text, text_ce);
@@ -636,7 +637,7 @@ gfc_diagnostic_start_span (const diagnostics::location_print_policy &loc_policy,
 static void
 gfc_diagnostic_text_finalizer (diagnostics::text_sink &text_output,
 			       const diagnostic_info *diagnostic ATTRIBUTE_UNUSED,
-			       diagnostic_t orig_diag_kind ATTRIBUTE_UNUSED)
+			       enum diagnostics::kind orig_diag_kind ATTRIBUTE_UNUSED)
 {
   pretty_printer *const pp = text_output.get_printer ();
   pp_destroy_prefix (pp);
@@ -655,7 +656,8 @@ gfc_warning_now_at (location_t loc, int opt, const char *gmsgid, ...)
   bool ret;
 
   va_start (argp, gmsgid);
-  diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_WARNING);
+  diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc,
+		       diagnostics::kind::warning);
   diagnostic.m_option_id = opt;
   ret = gfc_report_diagnostic (&diagnostic);
   va_end (argp);
@@ -674,7 +676,7 @@ gfc_warning_now (int opt, const char *gmsgid, ...)
 
   va_start (argp, gmsgid);
   diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc,
-		       DK_WARNING);
+		       diagnostics::kind::warning);
   diagnostic.m_option_id = opt;
   ret = gfc_report_diagnostic (&diagnostic);
   va_end (argp);
@@ -693,7 +695,7 @@ gfc_warning_internal (int opt, const char *gmsgid, ...)
 
   va_start (argp, gmsgid);
   diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc,
-		       DK_WARNING);
+		       diagnostics::kind::warning);
   diagnostic.m_option_id = opt;
   ret = gfc_report_diagnostic (&diagnostic);
   va_end (argp);
@@ -712,7 +714,8 @@ gfc_error_now (const char *gmsgid, ...)
   error_buffer->flag = true;
 
   va_start (argp, gmsgid);
-  diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_ERROR);
+  diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc,
+		       diagnostics::kind::error);
   gfc_report_diagnostic (&diagnostic);
   va_end (argp);
 }
@@ -728,7 +731,8 @@ gfc_fatal_error (const char *gmsgid, ...)
   rich_location rich_loc (line_table, UNKNOWN_LOCATION);
 
   va_start (argp, gmsgid);
-  diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_FATAL);
+  diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc,
+		       diagnostics::kind::fatal);
   gfc_report_diagnostic (&diagnostic);
   va_end (argp);
 
@@ -786,7 +790,8 @@ gfc_error_opt (int opt, const char *gmsgid, va_list ap)
   if (buffered_p)
     global_dc->set_diagnostic_buffer (pp_error_buffer);
 
-  diagnostic_set_info (&diagnostic, gmsgid, &argp, &richloc, DK_ERROR);
+  diagnostic_set_info (&diagnostic, gmsgid, &argp, &richloc,
+		       diagnostics::kind::error);
   gfc_report_diagnostic (&diagnostic);
 
   if (buffered_p)
@@ -831,7 +836,8 @@ gfc_internal_error (const char *gmsgid, ...)
     exit(EXIT_FAILURE);
 
   va_start (argp, gmsgid);
-  diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_ICE);
+  diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc,
+		       diagnostics::kind::ice);
   gfc_report_diagnostic (&diagnostic);
   va_end (argp);
 
diff --git a/gcc/fortran/options.cc b/gcc/fortran/options.cc
index d3c9066630b7..821a8c88bbbb 100644
--- a/gcc/fortran/options.cc
+++ b/gcc/fortran/options.cc
@@ -406,7 +406,8 @@ gfc_post_options (const char **pfilename)
       if (warn_line_truncation && !OPTION_SET_P (warnings_are_errors)
 	  && option_unspecified_p (OPT_Wline_truncation))
 	diagnostic_classify_diagnostic (global_dc, OPT_Wline_truncation,
-					DK_ERROR, UNKNOWN_LOCATION);
+					diagnostics::kind::error,
+					UNKNOWN_LOCATION);
     }
   else
     {
diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 0899018fdb6d..bfa588ee5f04 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -4207,7 +4207,8 @@ driver_handle_option (struct gcc_options *opts,
 
   gcc_assert (opts == &global_options);
   gcc_assert (opts_set == &global_options_set);
-  gcc_assert (kind == DK_UNSPECIFIED);
+  gcc_assert (static_cast<diagnostics::kind> (kind)
+	      == diagnostics::kind::unspecified);
   gcc_assert (loc == UNKNOWN_LOCATION);
   gcc_assert (dc == global_dc);
 
diff --git a/gcc/jit/dummy-frontend.cc b/gcc/jit/dummy-frontend.cc
index f917c6b9eadf..1de03745daf6 100644
--- a/gcc/jit/dummy-frontend.cc
+++ b/gcc/jit/dummy-frontend.cc
@@ -1016,7 +1016,7 @@ public:
   }
 
   void on_report_diagnostic (const diagnostic_info &info,
-			     diagnostic_t orig_diag_kind) final override
+			     enum diagnostics::kind orig_diag_kind) final override
   {
     JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
 
@@ -1056,7 +1056,7 @@ jit_begin_diagnostic (diagnostics::text_sink &,
 static void
 jit_end_diagnostic (diagnostics::text_sink &,
 		    const diagnostic_info *,
-		    diagnostic_t)
+		    enum diagnostics::kind)
 {
   gcc_assert (gcc::jit::active_playback_ctxt);
   JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
diff --git a/gcc/libgdiagnostics.cc b/gcc/libgdiagnostics.cc
index 0ac2cef1f9ac..9ae4d210e35f 100644
--- a/gcc/libgdiagnostics.cc
+++ b/gcc/libgdiagnostics.cc
@@ -1334,21 +1334,21 @@ private:
   std::unique_ptr<diagnostic_execution_path> m_path;
 };
 
-static diagnostic_t
-diagnostic_t_from_diagnostic_level (enum diagnostic_level level)
+static enum diagnostics::kind
+diagnostics_kind_from_diagnostic_level (enum diagnostic_level level)
 {
   switch (level)
     {
     default:
       gcc_unreachable ();
     case DIAGNOSTIC_LEVEL_ERROR:
-      return DK_ERROR;
+      return diagnostics::kind::error;
     case DIAGNOSTIC_LEVEL_WARNING:
-      return DK_WARNING;
+      return diagnostics::kind::warning;
     case DIAGNOSTIC_LEVEL_NOTE:
-      return DK_NOTE;
+      return diagnostics::kind::note;
     case DIAGNOSTIC_LEVEL_SORRY:
-      return DK_SORRY;
+      return diagnostics::kind::sorry;
     }
 }
 
@@ -1616,7 +1616,8 @@ diagnostic_manager::emit_va (diagnostic &diag, const char *msgid, va_list *args)
     diagnostic_info info;
 GCC_DIAGNOSTIC_PUSH_IGNORED(-Wsuggest-attribute=format)
     diagnostic_set_info (&info, msgid, args, diag.get_rich_location (),
-			 diagnostic_t_from_diagnostic_level (diag.get_level ()));
+			 diagnostics_kind_from_diagnostic_level
+			   (diag.get_level ()));
 GCC_DIAGNOSTIC_POP
     info.m_metadata = diag.get_metadata ();
     info.m_x_data = &diag;
diff --git a/gcc/lto-wrapper.cc b/gcc/lto-wrapper.cc
index ad204a778fd2..cb293f210993 100644
--- a/gcc/lto-wrapper.cc
+++ b/gcc/lto-wrapper.cc
@@ -2279,8 +2279,8 @@ public:
     return true;
   }
   char *make_option_name (diagnostics::option_id,
-			  diagnostic_t,
-			  diagnostic_t) const final override
+			  enum diagnostics::kind,
+			  enum diagnostics::kind) const final override
   {
     return nullptr;
   }
diff --git a/gcc/m2/gm2-gcc/m2linemap.cc b/gcc/m2/gm2-gcc/m2linemap.cc
index feb62b3ed4d8..0f0bd6541f1d 100644
--- a/gcc/m2/gm2-gcc/m2linemap.cc
+++ b/gcc/m2/gm2-gcc/m2linemap.cc
@@ -193,7 +193,8 @@ m2linemap_ErrorAtf_1 (location_t location, const char *message, ...)
   rich_location richloc (line_table, location);
 
   va_start (ap, message);
-  diagnostic_set_info (&diagnostic, message, &ap, &richloc, DK_ERROR);
+  diagnostic_set_info (&diagnostic, message, &ap, &richloc,
+		       diagnostics::kind::error);
   diagnostic_report_diagnostic (global_dc, &diagnostic);
   va_end (ap);
 }
@@ -214,7 +215,8 @@ m2linemap_WarningAtf_1 (location_t location, const char *message, ...)
   rich_location richloc (line_table, location);
 
   va_start (ap, message);
-  diagnostic_set_info (&diagnostic, message, &ap, &richloc, DK_WARNING);
+  diagnostic_set_info (&diagnostic, message, &ap, &richloc,
+		       diagnostics::kind::warning);
   diagnostic_report_diagnostic (global_dc, &diagnostic);
   va_end (ap);
 }
@@ -235,7 +237,8 @@ m2linemap_NoteAtf_1 (location_t location, const char *message, ...)
   rich_location richloc (line_table, location);
 
   va_start (ap, message);
-  diagnostic_set_info (&diagnostic, message, &ap, &richloc, DK_NOTE);
+  diagnostic_set_info (&diagnostic, message, &ap, &richloc,
+		       diagnostics::kind::note);
   diagnostic_report_diagnostic (global_dc, &diagnostic);
   va_end (ap);
 }
diff --git a/gcc/m2/gm2-gcc/rtegraph.cc b/gcc/m2/gm2-gcc/rtegraph.cc
index cd125823a062..b4cd6c26214f 100644
--- a/gcc/m2/gm2-gcc/rtegraph.cc
+++ b/gcc/m2/gm2-gcc/rtegraph.cc
@@ -393,15 +393,16 @@ const char *rtenode::create_message (const char *with_name, const char *without_
   return message;
 }
 
-/* error_message issue an DK_ERROR from grtenode.  */
+/* error_message issue an diagnostics::kind::error from grtenode.  */
 
 void rtenode::error_message (void)
 {
   if (grtenode != NULL)
-    generate_report (grtenode, "runtime error will occur", DK_ERROR);
+    generate_report (grtenode, "runtime error will occur",
+		     diagnostics::kind::error);
 }
 
-/* warning_message issue an DK_WARNING from grtenode.  */
+/* warning_message issue an diagnostics::kind::warning from grtenode.  */
 
 void rtenode::warning_message (void)
 {
@@ -409,15 +410,16 @@ void rtenode::warning_message (void)
     ("runtime error will occur if an exported procedure is called from %s",
      "runtime error will occur if an exported procedure is called");
   if (grtenode != NULL)
-    generate_report (grtenode, message, DK_WARNING);
+    generate_report (grtenode, message, diagnostics::kind::warning);
 }
 
-/* note_message issue an DK_NOTE from grtenode.  */
+/* note_message issue an diagnostics::kind::note from grtenode.  */
 
 void rtenode::note_message (void)
 {
   if (grtenode != NULL)
-    generate_report (grtenode, "runtime will occur if this procedure is called", DK_NOTE);
+    generate_report (grtenode, "runtime will occur if this procedure is called",
+		     diagnostics::kind::note);
 }
 
 /* dump_vec display contents of vector array list.  */
diff --git a/gcc/opts-common.cc b/gcc/opts-common.cc
index ebc23b4b00be..91cad49b9bd7 100644
--- a/gcc/opts-common.cc
+++ b/gcc/opts-common.cc
@@ -1282,9 +1282,9 @@ keep:
 
 /* Handle option DECODED for the language indicated by LANG_MASK,
    using the handlers in HANDLERS and setting fields in OPTS and
-   OPTS_SET.  KIND is the diagnostic_t if this is a diagnostics
-   option, DK_UNSPECIFIED otherwise, and LOC is the location of the
-   option for options from the source file, UNKNOWN_LOCATION
+   OPTS_SET.  KIND is the enum diagnostics::kind if this is a diagnostics
+   option, diagnostics::kind::unspecified otherwise, and LOC is the location
+   of the option for options from the source file, UNKNOWN_LOCATION
    otherwise.  GENERATED_P is true for an option generated as part of
    processing another option or otherwise generated internally, false
    for one explicitly passed by the user.  control_warning_option
@@ -1645,7 +1645,8 @@ read_cmdline_option (struct gcc_options *opts,
 
   gcc_assert (!decoded->errors);
 
-  if (!handle_option (opts, opts_set, decoded, lang_mask, DK_UNSPECIFIED,
+  if (!handle_option (opts, opts_set, decoded, lang_mask,
+		      static_cast<int> (diagnostics::kind::unspecified),
 		      loc, handlers, false, dc))
     error_at (loc, "unrecognized command-line option %qs", opt);
 }
@@ -1668,8 +1669,10 @@ set_option (struct gcc_options *opts, struct gcc_options *opts_set,
   if (!flag_var)
     return;
 
-  if ((diagnostic_t) kind != DK_UNSPECIFIED && dc != NULL)
-    diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, loc);
+  if ((enum diagnostics::kind) kind != diagnostics::kind::unspecified
+      && dc != nullptr)
+    diagnostic_classify_diagnostic (dc, opt_index,
+				    (enum diagnostics::kind) kind, loc);
 
   if (opts_set != NULL)
     set_flag_var = option_flag_var (opt_index, opts_set);
@@ -1954,7 +1957,9 @@ control_warning_option (unsigned int opt_index, int kind, const char *arg,
   if (opt_index == OPT_SPECIAL_ignore || opt_index == OPT_SPECIAL_warn_removed)
     return;
   if (dc)
-    diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, loc);
+    diagnostic_classify_diagnostic (dc, opt_index,
+				    static_cast<enum diagnostics::kind> (kind),
+				    loc);
   if (imply)
     {
       /* -Werror=foo implies -Wfoo.  */
diff --git a/gcc/opts-diagnostic.h b/gcc/opts-diagnostic.h
index d6382892a6b6..4fa4ea8a6f5a 100644
--- a/gcc/opts-diagnostic.h
+++ b/gcc/opts-diagnostic.h
@@ -50,9 +50,10 @@ public:
   }
 
   int option_enabled_p (diagnostics::option_id option_id) const final override;
-  char *make_option_name (diagnostics::option_id option_id,
-			  diagnostic_t orig_diag_kind,
-			  diagnostic_t diag_kind) const final override;
+  char *
+  make_option_name (diagnostics::option_id option_id,
+		    enum diagnostics::kind orig_diag_kind,
+		    enum diagnostics::kind diag_kind) const final override;
 
 private:
   const diagnostics::context &m_context;
diff --git a/gcc/opts.cc b/gcc/opts.cc
index 3263d27764d8..2cf07e56b6c8 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
@@ -371,7 +371,8 @@ target_handle_option (struct gcc_options *opts,
 		      diagnostics::context *dc, void (*) (void))
 {
   gcc_assert (dc == global_dc);
-  gcc_assert (kind == DK_UNSPECIFIED);
+  gcc_assert (static_cast<diagnostics::kind> (kind)
+	      == diagnostics::kind::unspecified);
   return targetm_common.handle_option (opts, opts_set, decoded, loc);
 }
 
@@ -535,14 +536,18 @@ maybe_default_option (struct gcc_options *opts,
   if (enabled)
     handle_generated_option (opts, opts_set, default_opt->opt_index,
 			     default_opt->arg, default_opt->value,
-			     lang_mask, DK_UNSPECIFIED, loc,
+			     lang_mask,
+			     static_cast<int> (diagnostics::kind::unspecified),
+			     loc,
 			     handlers, true, dc);
   else if (default_opt->arg == NULL
 	   && !option->cl_reject_negative
 	   && !(option->flags & CL_PARAMS))
     handle_generated_option (opts, opts_set, default_opt->opt_index,
 			     default_opt->arg, !default_opt->value,
-			     lang_mask, DK_UNSPECIFIED, loc,
+			     lang_mask,
+			     static_cast<int> (diagnostics::kind::unspecified),
+			     loc,
 			     handlers, true, dc);
 }
 
@@ -3311,7 +3316,9 @@ common_handle_option (struct gcc_options *opts,
 
     case OPT_pedantic_errors:
       dc->m_pedantic_errors = 1;
-      control_warning_option (OPT_Wpedantic, DK_ERROR, NULL, value,
+      control_warning_option (OPT_Wpedantic,
+			      static_cast<int> (diagnostics::kind::error),
+			      NULL, value,
 			      loc, lang_mask,
 			      handlers, opts, opts_set,
                               dc);
@@ -3711,7 +3718,9 @@ enable_warning_as_error (const char *arg, int value, unsigned int lang_mask,
 	      "controls warnings", arg, new_option);
   else
     {
-      const diagnostic_t kind = value ? DK_ERROR : DK_WARNING;
+      const enum diagnostics::kind kind = (value
+					   ? diagnostics::kind::error
+					   : diagnostics::kind::warning);
       const char *arg = NULL;
 
       if (cl_options[option_index].flags & CL_JOINED)
@@ -3731,14 +3740,15 @@ enable_warning_as_error (const char *arg, int value, unsigned int lang_mask,
 char *
 compiler_diagnostic_option_manager::
 make_option_name (diagnostics::option_id option_id,
-		  diagnostic_t orig_diag_kind,
-		  diagnostic_t diag_kind) const
+		  enum diagnostics::kind orig_diag_kind,
+		  enum diagnostics::kind diag_kind) const
 {
   if (option_id.m_idx)
     {
       /* A warning classified as an error.  */
-      if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN)
-	  && diag_kind == DK_ERROR)
+      if ((orig_diag_kind == diagnostics::kind::warning
+	   || orig_diag_kind == diagnostics::kind::pedwarn)
+	  && diag_kind == diagnostics::kind::error)
 	return concat (cl_options[OPT_Werror_].opt_text,
 		       /* Skip over "-W".  */
 		       cl_options[option_id.m_idx].opt_text + 2,
@@ -3748,8 +3758,9 @@ make_option_name (diagnostics::option_id option_id,
 	return xstrdup (cl_options[option_id.m_idx].opt_text);
     }
   /* A warning without option classified as an error.  */
-  else if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN
-	    || diag_kind == DK_WARNING)
+  else if ((orig_diag_kind == diagnostics::kind::warning
+	    || orig_diag_kind == diagnostics::kind::pedwarn
+	    || diag_kind == diagnostics::kind::warning)
 	   && m_context.warning_as_error_requested_p ())
     return xstrdup (cl_options[OPT_Werror].opt_text);
   else
diff --git a/gcc/rtl-error.cc b/gcc/rtl-error.cc
index 06d060c06db2..04a449ccf318 100644
--- a/gcc/rtl-error.cc
+++ b/gcc/rtl-error.cc
@@ -28,7 +28,7 @@ along with GCC; see the file COPYING3.  If not see
 
 static location_t location_for_asm (const rtx_insn *);
 static void diagnostic_for_asm (const rtx_insn *, const char *, va_list *,
-				diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0);
+				enum diagnostics::kind) ATTRIBUTE_GCC_DIAG(2,0);
 
 /* Figure the location of the given INSN.  */
 static location_t
@@ -64,7 +64,7 @@ location_for_asm (const rtx_insn *insn)
    and each ASM_OPERANDS records its own source file and line.  */
 static void
 diagnostic_for_asm (const rtx_insn *insn, const char *msg, va_list *args_ptr,
-		    diagnostic_t kind)
+		    enum diagnostics::kind kind)
 {
   diagnostic_info diagnostic;
   rich_location richloc (line_table, location_for_asm (insn));
@@ -80,7 +80,7 @@ error_for_asm (const rtx_insn *insn, const char *gmsgid, ...)
   va_list ap;
 
   va_start (ap, gmsgid);
-  diagnostic_for_asm (insn, gmsgid, &ap, DK_ERROR);
+  diagnostic_for_asm (insn, gmsgid, &ap, diagnostics::kind::error);
   va_end (ap);
 }
 
@@ -90,7 +90,7 @@ warning_for_asm (const rtx_insn *insn, const char *gmsgid, ...)
   va_list ap;
 
   va_start (ap, gmsgid);
-  diagnostic_for_asm (insn, gmsgid, &ap, DK_WARNING);
+  diagnostic_for_asm (insn, gmsgid, &ap, diagnostics::kind::warning);
   va_end (ap);
 }
 
diff --git a/gcc/rust/backend/rust-tree.cc b/gcc/rust/backend/rust-tree.cc
index 6cba04b3c277..2302ffb55f2f 100644
--- a/gcc/rust/backend/rust-tree.cc
+++ b/gcc/rust/backend/rust-tree.cc
@@ -3848,16 +3848,18 @@ strip_top_quals (tree t)
 /* Print an error message for invalid use of an incomplete type.
    VALUE is the expression that was used (or 0 if that isn't known)
    and TYPE is the type that was invalid.  DIAG_KIND indicates the
-   type of diagnostic (see diagnostic.def).  */
+   type of diagnostic (see diagnostics/kinds.def).  */
 
 void
 cxx_incomplete_type_diagnostic (location_t loc, const_tree value,
-				const_tree type, diagnostic_t diag_kind)
+				const_tree type,
+				enum diagnostics::kind diag_kind)
 {
   //  bool is_decl = false, complained = false;
 
-  gcc_assert (diag_kind == DK_WARNING || diag_kind == DK_PEDWARN
-	      || diag_kind == DK_ERROR);
+  gcc_assert (diag_kind == diagnostics::kind::warning
+	      || diag_kind == diagnostics::kind::pedwarn
+	      || diag_kind == diagnostics::kind::error);
 
   /* Avoid duplicate error message.  */
   if (TREE_CODE (type) == ERROR_MARK)
@@ -5131,7 +5133,7 @@ complete_type_or_maybe_complain (tree type, tree value, tsubst_flags_t complain)
   else if (!COMPLETE_TYPE_P (type))
     {
       if (complain & tf_error)
-	cxx_incomplete_type_diagnostic (value, type, DK_ERROR);
+	cxx_incomplete_type_diagnostic (value, type, diagnostics::kind::error);
       note_failed_type_completion_for_satisfaction (type);
       return NULL_TREE;
     }
diff --git a/gcc/rust/backend/rust-tree.h b/gcc/rust/backend/rust-tree.h
index bb99684b2bf8..3630b0e6bdeb 100644
--- a/gcc/rust/backend/rust-tree.h
+++ b/gcc/rust/backend/rust-tree.h
@@ -3137,7 +3137,7 @@ extern bool reject_gcc_builtin (const_tree, location_t = UNKNOWN_LOCATION);
 extern tree resolve_nondeduced_context (tree, tsubst_flags_t);
 
 extern void cxx_incomplete_type_diagnostic (location_t, const_tree, const_tree,
-					    diagnostic_t);
+					    enum diagnostics::kind);
 
 extern void cxx_incomplete_type_error (location_t, const_tree, const_tree);
 
@@ -3430,7 +3430,7 @@ null_node_p (const_tree expr)
 
 inline void
 cxx_incomplete_type_diagnostic (const_tree value, const_tree type,
-				diagnostic_t diag_kind)
+				enum diagnostics::kind diag_kind)
 {
   cxx_incomplete_type_diagnostic (rs_expr_loc_or_input_loc (value), value, type,
 				  diag_kind);
@@ -3439,7 +3439,7 @@ cxx_incomplete_type_diagnostic (const_tree value, const_tree type,
 inline void
 cxx_incomplete_type_error (const_tree value, const_tree type)
 {
-  cxx_incomplete_type_diagnostic (value, type, DK_ERROR);
+  cxx_incomplete_type_diagnostic (value, type, diagnostics::kind::error);
 }
 
 extern location_t
diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.cc b/gcc/rust/resolve/rust-ast-resolve-expr.cc
index 6f6f2bf0bfd9..5524e18ab5f7 100644
--- a/gcc/rust/resolve/rust-ast-resolve-expr.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc
@@ -130,7 +130,7 @@ ResolveExpr::visit (AST::IdentifierExpr &expr)
 	 and use the lower-level emit_diagnostic () instead of the more common
 	 internal_error_no_backtrace () in order to pass our locus.  */
       diagnostics::text_finalizer (global_dc) = funny_ice_text_finalizer;
-      emit_diagnostic (DK_ICE_NOBT, expr.get_locus (), -1,
+      emit_diagnostic (diagnostics::kind::ice_nobt, expr.get_locus (), -1,
 		       "are you trying to break %s? how dare you?",
 		       expr.as_string ().c_str ());
     }
diff --git a/gcc/rust/resolve/rust-ice-finalizer.cc b/gcc/rust/resolve/rust-ice-finalizer.cc
index 9e71531a6add..2a0cd3bbd3ca 100644
--- a/gcc/rust/resolve/rust-ice-finalizer.cc
+++ b/gcc/rust/resolve/rust-ice-finalizer.cc
@@ -24,9 +24,9 @@ namespace Resolver {
 void ATTRIBUTE_NORETURN
 funny_ice_text_finalizer (diagnostics::text_sink &text_output,
 			  const diagnostic_info *diagnostic,
-			  diagnostic_t diag_kind)
+			  enum diagnostics::kind diag_kind)
 {
-  gcc_assert (diag_kind == DK_ICE_NOBT);
+  gcc_assert (diag_kind == diagnostics::kind::ice_nobt);
   diagnostics::default_text_finalizer (text_output, diagnostic, diag_kind);
   fnotice (stderr, "You have broken GCC Rust. This is a feature.\n");
   exit (ICE_EXIT_CODE);
diff --git a/gcc/rust/resolve/rust-ice-finalizer.h b/gcc/rust/resolve/rust-ice-finalizer.h
index 6759e67c739c..f36e5582e5c1 100644
--- a/gcc/rust/resolve/rust-ice-finalizer.h
+++ b/gcc/rust/resolve/rust-ice-finalizer.h
@@ -57,7 +57,7 @@ namespace Resolver {
 void ATTRIBUTE_NORETURN
 funny_ice_text_finalizer (diagnostics::text_sink &text_output,
 			  const diagnostic_info *diagnostic,
-			  diagnostic_t diag_kind);
+			  enum diagnostics::kind diag_kind);
 
 } // namespace Resolver
 } // namespace Rust
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index fe9dea8fa62b..a15e17ff9a7f 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -376,7 +376,7 @@ Late::visit (AST::IdentifierExpr &expr)
   else if (funny_error)
     {
       diagnostics::text_finalizer (global_dc) = Resolver::funny_ice_text_finalizer;
-      emit_diagnostic (DK_ICE_NOBT, expr.get_locus (), -1,
+      emit_diagnostic (diagnostics::kind::ice_nobt, expr.get_locus (), -1,
 		       "are you trying to break %s? how dare you?",
 		       expr.as_string ().c_str ());
     }
diff --git a/gcc/substring-locations.cc b/gcc/substring-locations.cc
index 59affc60a965..9bbc76bec8c1 100644
--- a/gcc/substring-locations.cc
+++ b/gcc/substring-locations.cc
@@ -218,11 +218,11 @@ format_string_diagnostic_t::emit_warning_n_va (diagnostics::option_id option_id,
 
       const char *text = ngettext (singular_gmsgid, plural_gmsgid, gtn);
       diagnostic_set_info_translated (&diagnostic, text, ap, &richloc,
-				      DK_WARNING);
+				      diagnostics::kind::warning);
     }
   else
     diagnostic_set_info (&diagnostic, singular_gmsgid, ap, &richloc,
-			 DK_WARNING);
+			 diagnostics::kind::warning);
   diagnostic.m_option_id = option_id;
   bool warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
 
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc
index cae5b648b83b..5ac23436cd80 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc
@@ -132,7 +132,7 @@ static bool force_show_locus_color = false;
 static void
 custom_diagnostic_text_finalizer (diagnostics::text_sink &text_output,
 				  const diagnostic_info *diagnostic,
-				  diagnostic_t)
+				  enum diagnostics::kind)
 {
   pretty_printer *const pp = text_output.get_printer ();
   bool old_show_color = pp_show_color (pp);
diff --git a/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.cc b/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.cc
index bad14617a484..ea37921acacb 100644
--- a/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.cc
+++ b/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.cc
@@ -49,7 +49,8 @@ test_richloc (rich_location *richloc)
   /* Run the diagnostic and fix-it printing code.  */
   diagnostics::selftest::test_context dc;
   diagnostic_show_locus (&dc, dc.m_source_printing,
-			 richloc, DK_ERROR, dc.get_reference_printer ());
+			 richloc, diagnostics::kind::error,
+			 dc.get_reference_printer ());
 
   /* Generate a diff.  */
   diagnostics::changes::change_set edit (global_dc->get_file_cache ());
diff --git a/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.cc b/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.cc
index d45a33d168fe..bd8019a701f4 100644
--- a/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.cc
+++ b/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.cc
@@ -44,7 +44,7 @@ static diagnostics::text_finalizer_fn original_text_finalizer = NULL;
 static void
 verify_unpacked_ranges  (diagnostics::text_sink &text_output,
 			 const diagnostic_info *diagnostic,
-			 diagnostic_t orig_diag_kind)
+			 enum diagnostics::kind orig_diag_kind)
 {
   /* Verify that the locations are ad-hoc, not packed. */
   location_t loc = diagnostic_location (diagnostic);
@@ -58,7 +58,7 @@ verify_unpacked_ranges  (diagnostics::text_sink &text_output,
 static void
 verify_no_columns  (diagnostics::text_sink &text_output,
 		    const diagnostic_info *diagnostic,
-		    diagnostic_t orig_diag_kind)
+		    enum diagnostics::kind orig_diag_kind)
 {
   /* Verify that the locations have no columns. */
   location_t loc = diagnostic_location (diagnostic);
diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
index 312c4b8659a4..859a943a3b10 100644
--- a/gcc/testsuite/lib/gcc-dg.exp
+++ b/gcc/testsuite/lib/gcc-dg.exp
@@ -1338,8 +1338,8 @@ proc dg-missed { args } {
 }
 
 # Look for messages with 'note: ' prefixes.
-# In addition to standard compiler diagnostics ('DK_NOTE', 'inform' functions,
-# "for additional details on an error message"),
+# In addition to standard compiler diagnostics (diagnostics::kind::note,
+# 'inform' functions, "for additional details on an error message"),
 # this also includes output from '-fopt-info' for 'MSG_NOTE':
 # a general optimization info.
 # By default, any *excess* notes are pruned, meaning their appearance doesn't
diff --git a/gcc/toplev.cc b/gcc/toplev.cc
index f7532826459e..4a230f72116e 100644
--- a/gcc/toplev.cc
+++ b/gcc/toplev.cc
@@ -1748,11 +1748,13 @@ process_options ()
       if (warn_coverage_mismatch
 	  && option_unspecified_p (OPT_Wcoverage_mismatch))
 	diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_mismatch,
-					DK_ERROR, UNKNOWN_LOCATION);
+					diagnostics::kind::error,
+					UNKNOWN_LOCATION);
       if (warn_coverage_invalid_linenum
 	  && option_unspecified_p (OPT_Wcoverage_invalid_line_number))
 	diagnostic_classify_diagnostic (global_dc, OPT_Wcoverage_invalid_line_number,
-					DK_ERROR, UNKNOWN_LOCATION);
+					diagnostics::kind::error,
+					UNKNOWN_LOCATION);
     }
 
   /* Save the current optimization options.  */
diff --git a/libcpp/internal.h b/libcpp/internal.h
index 9973836068b0..8ca4c75b6ccf 100644
--- a/libcpp/internal.h
+++ b/libcpp/internal.h
@@ -622,8 +622,8 @@ struct cpp_reader
      zero of said file.  */
   location_t main_loc;
 
-  /* If non-zero, override diagnostic locations (other than DK_NOTE
-     diagnostics) to this one.  */
+  /* If non-zero, override diagnostic locations (other than
+     diagnostics::kind::note diagnostics) to this one.  */
   location_t diagnostic_override_loc;
 
   /* Returns true iff we should warn about UTF-8 bidirectional control
-- 
2.26.3

