public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-4237] d: Merge upstream dmd, druntime 4574d1728d, phobos d7e79f024.
@ 2023-09-23 11:01 Iain Buclaw
  0 siblings, 0 replies; only message in thread
From: Iain Buclaw @ 2023-09-23 11:01 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:d6679fa2d65316e80a267c94c17ad9e23f433f77

commit r14-4237-gd6679fa2d65316e80a267c94c17ad9e23f433f77
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Sat Sep 23 12:27:26 2023 +0200

    d: Merge upstream dmd, druntime 4574d1728d, phobos d7e79f024.
    
    D front-end changes:
    
            - Import dmd v2.105.0.
            - Catch clause must take only `const' or mutable exceptions.
            - Creating a `scope' class instance with a non-scope constructor
              is now `@system' only with `-fpreview=dip1000'.
            - Global `const' variables can no longer be initialized from a
              non-shared static constructor
    
    D runtime changes:
    
            - Import druntime v2.105.0.
    
    Phobos changes:
    
            - Import phobos v2.105.0.
    
    gcc/d/ChangeLog:
    
            * dmd/MERGE: Merge upstream dmd 4574d1728d.
            * dmd/VERSION: Bump version to v2.105.0.
            * d-diagnostic.cc (verror): Remove.
            (verrorSupplemental): Remove.
            (vwarning): Remove.
            (vwarningSupplemental): Remove.
            (vdeprecation): Remove.
            (vdeprecationSupplemental): Remove.
            (vmessage): Remove.
            (vtip): Remove.
            (verrorReport): New function.
            (verrorReportSupplemental): New function.
            * d-lang.cc (d_parse_file): Update for new front-end interface.
            * decl.cc (d_mangle_decl): Update for new front-end interface.
            * intrinsics.cc (maybe_set_intrinsic): Update for new front-end
            interface.
    
    libphobos/ChangeLog:
    
            * libdruntime/MERGE: Merge upstream druntime 4574d1728d.
            * src/MERGE: Merge upstream phobos d7e79f024.

Diff:
---
 gcc/d/d-diagnostic.cc                              | 199 ++++++--------
 gcc/d/d-lang.cc                                    |   6 +-
 gcc/d/decl.cc                                      |   2 +-
 gcc/d/dmd/MERGE                                    |   2 +-
 gcc/d/dmd/README.md                                |   3 +-
 gcc/d/dmd/VERSION                                  |   2 +-
 gcc/d/dmd/access.d                                 |   1 -
 gcc/d/dmd/aggregate.d                              |   2 +-
 gcc/d/dmd/aliasthis.d                              |   3 +-
 gcc/d/dmd/arrayop.d                                |  10 +-
 gcc/d/dmd/attrib.d                                 |  47 ++--
 gcc/d/dmd/blockexit.d                              |   1 -
 gcc/d/dmd/canthrow.d                               |   3 +-
 gcc/d/dmd/common/file.d                            |   8 +
 gcc/d/dmd/common/outbuffer.d                       |  12 +-
 gcc/d/dmd/common/string.d                          |   5 +-
 gcc/d/dmd/cond.d                                   |  16 +-
 gcc/d/dmd/constfold.d                              |   4 +-
 gcc/d/dmd/cppmangle.d                              |  18 +-
 gcc/d/dmd/ctfeexpr.d                               |  24 +-
 gcc/d/dmd/ctorflow.d                               |   8 +-
 gcc/d/dmd/dclass.d                                 |   2 +-
 gcc/d/dmd/declaration.d                            |  30 +-
 gcc/d/dmd/declaration.h                            |   4 +-
 gcc/d/dmd/delegatize.d                             |   4 +-
 gcc/d/dmd/dinterpret.d                             |  17 +-
 gcc/d/dmd/dmangle.d                                |  66 ++---
 gcc/d/dmd/dmodule.d                                |   6 +-
 gcc/d/dmd/doc.d                                    |  99 ++++---
 gcc/d/dmd/doc.h                                    |   3 +-
 gcc/d/dmd/dscope.d                                 |  15 +-
 gcc/d/dmd/dsymbol.d                                |  52 ++--
 gcc/d/dmd/dsymbolsem.d                             |  30 +-
 gcc/d/dmd/dtemplate.d                              |  22 +-
 gcc/d/dmd/dtoh.d                                   |  23 +-
 gcc/d/dmd/dversion.d                               |   8 +-
 gcc/d/dmd/errors.d                                 | 180 +++++-------
 gcc/d/dmd/errors.h                                 |  20 +-
 gcc/d/dmd/errorsink.d                              |   6 +
 gcc/d/dmd/escape.d                                 |   2 +-
 gcc/d/dmd/expression.d                             | 303 +++++++++++----------
 gcc/d/dmd/expression.h                             |   1 +
 gcc/d/dmd/expressionsem.d                          |  49 +++-
 gcc/d/dmd/foreachvar.d                             |   2 +-
 gcc/d/dmd/func.d                                   |  17 +-
 gcc/d/dmd/globals.d                                |  18 +-
 gcc/d/dmd/globals.h                                |   2 +-
 gcc/d/dmd/hdrgen.d                                 |  16 +-
 gcc/d/dmd/id.d                                     |   8 +-
 gcc/d/dmd/identifier.d                             |   6 +-
 gcc/d/dmd/imphint.d                                |   2 +-
 gcc/d/dmd/init.d                                   |  14 +-
 gcc/d/dmd/intrange.d                               |  50 ++--
 gcc/d/dmd/json.d                                   |   2 +-
 gcc/d/dmd/lambdacomp.d                             |   2 +-
 gcc/d/dmd/lexer.d                                  |   2 +-
 gcc/d/dmd/location.d                               |   6 +-
 gcc/d/dmd/mangle.h                                 |   8 +-
 gcc/d/dmd/mtype.d                                  |  76 +++---
 gcc/d/dmd/mtype.h                                  |   3 +-
 gcc/d/dmd/mustuse.d                                |   4 +-
 gcc/d/dmd/nogc.d                                   |   8 +-
 gcc/d/dmd/ob.d                                     |   6 +-
 gcc/d/dmd/objc.d                                   |   8 +-
 gcc/d/dmd/opover.d                                 |   4 +-
 gcc/d/dmd/parse.d                                  | 264 +++++++++---------
 gcc/d/dmd/postordervisitor.d                       |   2 +-
 gcc/d/dmd/printast.d                               |   2 +-
 gcc/d/dmd/root/complex.d                           |   8 +-
 gcc/d/dmd/root/filename.d                          |   9 +-
 gcc/d/dmd/root/longdouble.d                        |   3 +
 gcc/d/dmd/root/rmem.d                              |   2 +-
 gcc/d/dmd/root/utf.d                               |  10 +-
 gcc/d/dmd/sapply.d                                 |   2 +-
 gcc/d/dmd/scope.h                                  |   2 +
 gcc/d/dmd/semantic2.d                              |   7 +-
 gcc/d/dmd/semantic3.d                              |  10 +-
 gcc/d/dmd/sideeffect.d                             |   4 +-
 gcc/d/dmd/statement.d                              | 126 ++++-----
 gcc/d/dmd/statement.h                              |   1 +
 gcc/d/dmd/statementsem.d                           |  32 ++-
 gcc/d/dmd/target.d                                 |  10 +-
 gcc/d/dmd/templateparamsem.d                       |   2 +-
 gcc/d/dmd/tokens.d                                 |   2 +-
 gcc/d/dmd/typesem.d                                |  17 +-
 gcc/d/dmd/visitor.d                                |   2 +-
 gcc/d/intrinsics.cc                                |   2 +-
 gcc/testsuite/gdc.test/compilable/test23145.d      |  14 +-
 .../gdc.test/fail_compilation/biterrors3.d         |   4 +-
 gcc/testsuite/gdc.test/fail_compilation/bug8891.d  |   2 +-
 .../gdc.test/fail_compilation/deprecatedinref.d    |  10 -
 .../gdc.test/fail_compilation/diag15209.d          |   4 +-
 gcc/testsuite/gdc.test/fail_compilation/diag9451.d |  11 +-
 gcc/testsuite/gdc.test/fail_compilation/diag9635.d |   4 +-
 .../fail_compilation/dip1000_deprecation.d         |  20 +-
 gcc/testsuite/gdc.test/fail_compilation/e15876_6.d |   2 +-
 .../gdc.test/fail_compilation/fail10285.d          |  13 +-
 .../gdc.test/fail_compilation/fail11545.d          |   4 +-
 gcc/testsuite/gdc.test/fail_compilation/fail120.d  |   4 +-
 gcc/testsuite/gdc.test/fail_compilation/fail142.d  |   5 +-
 gcc/testsuite/gdc.test/fail_compilation/fail143.d  |   2 +-
 gcc/testsuite/gdc.test/fail_compilation/fail144.d  |   2 +-
 gcc/testsuite/gdc.test/fail_compilation/fail145.d  |   2 +-
 .../gdc.test/fail_compilation/fail17955.d          |  27 +-
 .../gdc.test/fail_compilation/fail20538.d          |   6 +-
 gcc/testsuite/gdc.test/fail_compilation/fail25.d   |   2 +-
 gcc/testsuite/gdc.test/fail_compilation/fail301.d  |   2 +-
 gcc/testsuite/gdc.test/fail_compilation/fail46.d   |   2 +-
 gcc/testsuite/gdc.test/fail_compilation/fail4923.d |   8 +-
 gcc/testsuite/gdc.test/fail_compilation/fail50.d   |   2 +-
 gcc/testsuite/gdc.test/fail_compilation/fail61.d   |   2 +-
 gcc/testsuite/gdc.test/fail_compilation/fail66.d   |   4 +-
 gcc/testsuite/gdc.test/fail_compilation/fail7851.d |   6 +-
 gcc/testsuite/gdc.test/fail_compilation/fail9613.d |   2 +-
 .../gdc.test/fail_compilation/fail_scope.d         |   4 +-
 .../gdc.test/fail_compilation/failcontracts.d      |  17 +-
 gcc/testsuite/gdc.test/fail_compilation/ice15332.d |   4 +-
 gcc/testsuite/gdc.test/fail_compilation/ice15922.d |   2 +-
 gcc/testsuite/gdc.test/fail_compilation/ice20056.d |   2 +-
 gcc/testsuite/gdc.test/fail_compilation/ice7645.d  |   4 +-
 gcc/testsuite/gdc.test/fail_compilation/ice9439.d  |   2 +-
 .../fail_compilation/misc_parser_err_cov1.d        |   2 +-
 .../gdc.test/fail_compilation/mixintype2.d         |   8 +-
 gcc/testsuite/gdc.test/fail_compilation/noreturn.d |  14 +-
 .../gdc.test/fail_compilation/noreturn2.d          |  13 +
 .../gdc.test/fail_compilation/systemvariables.d    |  27 +-
 .../gdc.test/fail_compilation/test13536.d          |   4 +-
 .../gdc.test/fail_compilation/test16365.d          |   4 +-
 .../gdc.test/fail_compilation/test21008.d          |   4 +-
 gcc/testsuite/gdc.test/fail_compilation/test9701.d |  42 +--
 gcc/testsuite/gdc.test/runnable/aliasthis.d        |  10 -
 gcc/testsuite/gdc.test/runnable/complex.d          |  56 ++--
 gcc/testsuite/gdc.test/runnable/interpret.d        |   8 +-
 gcc/testsuite/gdc.test/runnable/template9.d        |   2 +-
 gcc/testsuite/gdc.test/runnable/test17684.d        |  10 -
 gcc/testsuite/gdc.test/runnable/test19782.d        |   8 -
 gcc/testsuite/gdc.test/runnable/test20.d           |   4 +-
 gcc/testsuite/gdc.test/runnable/test21039.d        |   7 -
 gcc/testsuite/gdc.test/runnable/test23234.d        |   7 -
 gcc/testsuite/gdc.test/runnable/test3449.d         |   2 +-
 gcc/testsuite/gdc.test/runnable/test42.d           |   2 +-
 gcc/testsuite/gdc.test/runnable/testaliascast.d    |   8 -
 gcc/testsuite/gdc.test/runnable/testassign.d       |   6 +-
 gcc/testsuite/gdc.test/runnable/testconst.d        |   6 +-
 gcc/testsuite/gdc.test/runnable/testswitch.d       |   8 +-
 .../gdc.test/runnable/traits_getPointerBitmap.d    |  29 ++
 gcc/testsuite/gdc.test/runnable/xtest46.d          |   4 -
 gcc/testsuite/gdc.test/runnable/xtest46_gc.d       |   4 -
 libphobos/libdruntime/MERGE                        |   2 +-
 libphobos/libdruntime/core/demangle.d              |  12 +-
 .../libdruntime/core/internal/array/appending.d    |   4 +-
 .../libdruntime/core/internal/array/capacity.d     |   2 +-
 .../libdruntime/core/internal/array/construction.d |   4 +-
 libphobos/libdruntime/core/memory.d                |   8 +-
 libphobos/libdruntime/core/sys/windows/basetsd.d   |  31 +--
 libphobos/libdruntime/core/sys/windows/mmsystem.d  |  22 +-
 libphobos/libdruntime/core/sys/windows/ole.d       |   2 +-
 libphobos/libdruntime/core/sys/windows/ras.d       |   2 +-
 libphobos/libdruntime/core/sys/windows/rpcdcep.d   |   2 +-
 libphobos/libdruntime/core/sys/windows/rpcndr.d    |   2 +-
 libphobos/libdruntime/core/sys/windows/sqltypes.d  |   2 +-
 libphobos/libdruntime/core/sys/windows/vfw.d       |  16 +-
 libphobos/libdruntime/core/sys/windows/winbase.d   |   2 +-
 libphobos/libdruntime/core/sys/windows/wingdi.d    | 100 +++----
 libphobos/libdruntime/core/sys/windows/winuser.d   |   4 +-
 libphobos/libdruntime/object.d                     |  96 ++++++-
 libphobos/src/MERGE                                |   2 +-
 libphobos/src/std/array.d                          |  38 ++-
 libphobos/src/std/conv.d                           |  95 ++++---
 libphobos/src/std/digest/md.d                      |   3 +-
 libphobos/src/std/digest/sha.d                     |   4 +-
 libphobos/src/std/exception.d                      |  25 +-
 libphobos/src/std/format/internal/write.d          |  26 +-
 libphobos/src/std/int128.d                         | 273 +++++++++++++++++--
 libphobos/src/std/json.d                           |  53 ++--
 libphobos/src/std/math/package.d                   |   2 +-
 libphobos/src/std/range/package.d                  |  13 +-
 libphobos/src/std/regex/internal/ir.d              |   2 +-
 libphobos/src/std/socket.d                         |  56 ++--
 libphobos/src/std/stdio.d                          |  68 +++--
 libphobos/src/std/traits.d                         |  84 ++----
 libphobos/src/std/uni/package.d                    |   9 +
 182 files changed, 2002 insertions(+), 1665 deletions(-)

diff --git a/gcc/d/d-diagnostic.cc b/gcc/d/d-diagnostic.cc
index 7e5b17c46e5..57f36f2f8dd 100644
--- a/gcc/d/d-diagnostic.cc
+++ b/gcc/d/d-diagnostic.cc
@@ -218,139 +218,116 @@ d_diagnostic_report_diagnostic (const Loc &loc, int opt, const char *format,
   va_end (argp);
 }
 
-/* Print a hard error message with explicit location LOC with an optional
-   message prefix PREFIX1 and PREFIX2, increasing the global or gagged
-   error count.  */
+/* Print a diagnostic message of type KIND with explicit location LOC with an
+   optional message prefix PREFIX1 and PREFIX2, increasing the global or gagged
+   error count depending on how KIND is treated.  */
 
-void ATTRIBUTE_GCC_DIAG(2,0)
-verror (const Loc &loc, const char *format, va_list ap,
-	const char *prefix1, const char *prefix2, const char *)
+void D_ATTRIBUTE_FORMAT(2,0) ATTRIBUTE_GCC_DIAG(2,0)
+verrorReport (const Loc& loc, const char *format, va_list ap, ErrorKind kind,
+	      const char *prefix1 = NULL, const char *prefix2 = NULL)
 {
-  if (!global.gag || global.params.showGaggedErrors)
-    {
-      char *xformat;
-
-      /* Build string and emit.  */
-      if (prefix2 != NULL)
-	xformat = xasprintf ("%s %s %s", escape_d_format (prefix1),
-			     escape_d_format (prefix2), format);
-      else if (prefix1 != NULL)
-	xformat = xasprintf ("%s %s", escape_d_format (prefix1), format);
-      else
-	xformat = xasprintf ("%s", format);
-
-      d_diagnostic_report_diagnostic (loc, 0, xformat, ap,
-				      global.gag ? DK_ANACHRONISM : DK_ERROR,
-				      false);
-      free (xformat);
-    }
-
-  if (global.gag)
-    global.gaggedErrors++;
+  diagnostic_t diag_kind = DK_UNSPECIFIED;
+  int opt = 0;
+  bool verbatim = false;
+  char *xformat;
 
-  global.errors++;
-}
-
-/* Print supplementary message about the last error with explicit location LOC.
-   This doesn't increase the global error count.  */
+  if (kind == ErrorKind::error)
+    {
+      global.errors++;
+      if (global.gag)
+	global.gaggedErrors++;
 
-void ATTRIBUTE_GCC_DIAG(2,0)
-verrorSupplemental (const Loc &loc, const char *format, va_list ap)
-{
-  if (global.gag && !global.params.showGaggedErrors)
-    return;
+      if (global.gag && !global.params.showGaggedErrors)
+	return;
 
-  d_diagnostic_report_diagnostic (loc, 0, format, ap, DK_NOTE, false);
-}
+      diag_kind = global.gag ? DK_ANACHRONISM : DK_ERROR;
+    }
+  else if (kind == ErrorKind::warning)
+    {
+      if (global.gag || global.params.warnings == DIAGNOSTICoff)
+	{
+	  if (global.gag)
+	    global.gaggedWarnings++;
 
-/* Print a warning message with explicit location LOC, increasing the
-   global warning count.  */
+	  return;
+	}
 
-void ATTRIBUTE_GCC_DIAG(2,0)
-vwarning (const Loc &loc, const char *format, va_list ap)
-{
-  if (!global.gag && global.params.warnings != DIAGNOSTICoff)
-    {
       /* Warnings don't count if not treated as errors.  */
       if (global.params.warnings == DIAGNOSTICerror)
 	global.warnings++;
 
-      d_diagnostic_report_diagnostic (loc, 0, format, ap, DK_WARNING, false);
+      diag_kind = DK_WARNING;
     }
-  else if (global.gag)
-    global.gaggedWarnings++;
-}
-
-/* Print supplementary message about the last warning with explicit location
-   LOC.  This doesn't increase the global warning count.  */
-
-void ATTRIBUTE_GCC_DIAG(2,0)
-vwarningSupplemental (const Loc &loc, const char *format, va_list ap)
-{
-  if (global.params.warnings == DIAGNOSTICoff || global.gag)
-    return;
-
-  d_diagnostic_report_diagnostic (loc, 0, format, ap, DK_NOTE, false);
-}
+  else if (kind == ErrorKind::deprecation)
+    {
+      if (global.params.useDeprecated == DIAGNOSTICerror)
+	return verrorReport (loc, format, ap, ErrorKind::error, prefix1,
+			     prefix2);
+      else if (global.gag || global.params.useDeprecated != DIAGNOSTICinform)
+	{
+	  if (global.gag)
+	    global.gaggedWarnings++;
 
-/* Print a deprecation message with explicit location LOC with an optional
-   message prefix PREFIX1 and PREFIX2, increasing the global warning or
-   error count depending on how deprecations are treated.  */
+	  return;
+	}
 
-void ATTRIBUTE_GCC_DIAG(2,0)
-vdeprecation (const Loc &loc, const char *format, va_list ap,
-	      const char *prefix1, const char *prefix2)
-{
-  if (global.params.useDeprecated == DIAGNOSTICerror)
-    verror (loc, format, ap, prefix1, prefix2);
-  else if (global.params.useDeprecated == DIAGNOSTICinform && !global.gag)
+      opt = OPT_Wdeprecated;
+      diag_kind = DK_WARNING;
+    }
+  else if (kind == ErrorKind::message)
     {
-      char *xformat;
-
-      /* Build string and emit.  */
-      if (prefix2 != NULL)
-	xformat = xasprintf ("%s %s %s", escape_d_format (prefix1),
-			     escape_d_format (prefix2), format);
-      else if (prefix1 != NULL)
-	xformat = xasprintf ("%s %s", escape_d_format (prefix1), format);
-      else
-	xformat = xasprintf ("%s", format);
-
-      d_diagnostic_report_diagnostic (loc, OPT_Wdeprecated, xformat, ap,
-				      DK_WARNING, false);
-      free (xformat);
+      diag_kind = DK_NOTE;
+      verbatim = true;
     }
-  else if (global.gag)
-    global.gaggedWarnings++;
-}
-
-/* Print supplementary message about the last deprecation with explicit
-   location LOC.  This does not increase the global error count.  */
+  else if (kind == ErrorKind::tip)
+    {
+      diag_kind = DK_DEBUG;
+      verbatim = true;
+    }
+  else
+    gcc_unreachable ();
+
+  /* Build string and emit.  */
+  if (prefix2 != NULL)
+    xformat = xasprintf ("%s %s %s", escape_d_format (prefix1),
+			 escape_d_format (prefix2), format);
+  else if (prefix1 != NULL)
+    xformat = xasprintf ("%s %s", escape_d_format (prefix1), format);
+  else
+    xformat = xasprintf ("%s", format);
 
-void ATTRIBUTE_GCC_DIAG(2,0)
-vdeprecationSupplemental (const Loc &loc, const char *format, va_list ap)
-{
-  if (global.params.useDeprecated == DIAGNOSTICerror)
-    verrorSupplemental (loc, format, ap);
-  else if (global.params.useDeprecated == DIAGNOSTICinform && !global.gag)
-    d_diagnostic_report_diagnostic (loc, 0, format, ap, DK_NOTE, false);
+  d_diagnostic_report_diagnostic (loc, opt, xformat, ap, diag_kind, verbatim);
+  free (xformat);
 }
 
-/* Print a verbose message with explicit location LOC.  */
+/* Print supplementary message about the last diagnostic of type KIND, with
+   explicit location LOC.  This doesn't increase the global error count.  */
 
-void ATTRIBUTE_GCC_DIAG(2,0)
-vmessage (const Loc &loc, const char *format, va_list ap)
+void D_ATTRIBUTE_FORMAT(2,0) ATTRIBUTE_GCC_DIAG(2,0)
+verrorReportSupplemental (const Loc& loc, const char* format, va_list ap,
+			  ErrorKind kind)
 {
-  d_diagnostic_report_diagnostic (loc, 0, format, ap, DK_NOTE, true);
-}
-
-/* Print a tip message with prefix and highlighing.  */
+  if (kind == ErrorKind::error)
+    {
+      if (global.gag && !global.params.showGaggedErrors)
+	return;
+    }
+  else if (kind == ErrorKind::warning)
+    {
+      if (global.params.warnings == DIAGNOSTICoff || global.gag)
+	return;
+    }
+  else if (kind == ErrorKind::deprecation)
+    {
+      if (global.params.useDeprecated == DIAGNOSTICerror)
+	return verrorReportSupplemental (loc, format, ap, ErrorKind::error);
+      else if (global.params.useDeprecated != DIAGNOSTICinform || global.gag)
+	return;
+    }
+  else
+    gcc_unreachable ();
 
-void ATTRIBUTE_GCC_DIAG(1,0)
-vtip (const char *format, va_list ap)
-{
-  if (!global.gag)
-    d_diagnostic_report_diagnostic (Loc (), 0, format, ap, DK_DEBUG, true);
+  d_diagnostic_report_diagnostic (loc, 0, format, ap, DK_NOTE, false);
 }
 
 /* Call this after printing out fatal error messages to clean up and
diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 10b9000119e..7dddcf5ac91 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -1101,7 +1101,7 @@ d_parse_file (void)
 
       if (m->filetype == FileType::ddoc)
 	{
-	  gendocfile (m);
+	  gendocfile (m, global.errorSink);
 	  /* Remove M from list of modules.  */
 	  modules.remove (i);
 	  i--;
@@ -1256,7 +1256,7 @@ d_parse_file (void)
       /* Declare the name of the root module as the first global name in order
 	 to make the middle-end fully deterministic.  */
       OutBuffer buf;
-      mangleToBuffer (Module::rootModule, &buf);
+      mangleToBuffer (Module::rootModule, buf);
       first_global_object_name = buf.extractChars ();
     }
 
@@ -1337,7 +1337,7 @@ d_parse_file (void)
       for (size_t i = 0; i < modules.length; i++)
 	{
 	  Module *m = modules[i];
-	  gendocfile (m);
+	  gendocfile (m, global.errorSink);
 	}
     }
 
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index b866593880d..7e612e1cbbc 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -73,7 +73,7 @@ d_mangle_decl (Dsymbol *decl)
   else
     {
       OutBuffer buf;
-      mangleToBuffer (decl, &buf);
+      mangleToBuffer (decl, buf);
       return buf.extractChars ();
     }
 }
diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index a02a8cbaba5..dc267787cab 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-26f049fb26e755096dea3f1474decea7c0fef187
+4574d1728d1f7e52ff40e6733b8c39889d128349
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/gcc/d/dmd/README.md b/gcc/d/dmd/README.md
index 4fd7831866a..d0c75a5b14a 100644
--- a/gcc/d/dmd/README.md
+++ b/gcc/d/dmd/README.md
@@ -31,7 +31,8 @@ Note that these groups have no strict meaning, the category assignments are a bi
 
 | File                                                                        | Purpose                                                               |
 |-----------------------------------------------------------------------------|-----------------------------------------------------------------------|
-| [mars.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/mars.d)           | The entry point. Contains `main`.                                     |
+| [main.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/main.d)           | The entry point. Contains `main`.                                     |
+| [mars.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/mars.d)           | Argument parsing, path manipulation.                                  |
 | [cli.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/cli.d)             | Define the command line interface                                     |
 | [dmdparams.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/dmdparams.d) | DMD-specific parameters                                               |
 | [globals.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/globals.d)     | Define a structure storing command line options                       |
diff --git a/gcc/d/dmd/VERSION b/gcc/d/dmd/VERSION
index 6faa8d801e6..8012337e422 100644
--- a/gcc/d/dmd/VERSION
+++ b/gcc/d/dmd/VERSION
@@ -1 +1 @@
-v2.105.0-beta.1
+v2.105.0
diff --git a/gcc/d/dmd/access.d b/gcc/d/dmd/access.d
index 668129a5385..ab9b5d9da48 100644
--- a/gcc/d/dmd/access.d
+++ b/gcc/d/dmd/access.d
@@ -21,7 +21,6 @@ import dmd.dscope;
 import dmd.dstruct;
 import dmd.dsymbol;
 import dmd.expression;
-import dmd.globals;
 import dmd.location;
 import dmd.tokens;
 
diff --git a/gcc/d/dmd/aggregate.d b/gcc/d/dmd/aggregate.d
index 42b926be453..4ae6b6bc5cc 100644
--- a/gcc/d/dmd/aggregate.d
+++ b/gcc/d/dmd/aggregate.d
@@ -64,7 +64,7 @@ enum ClassKind : ubyte
  * Returns:
  *     0-terminated string for `c`
  */
-const(char)* toChars(ClassKind c)
+const(char)* toChars(ClassKind c) @safe
 {
     final switch (c)
     {
diff --git a/gcc/d/dmd/aliasthis.d b/gcc/d/dmd/aliasthis.d
index ce384593c59..a8933f6d2fe 100644
--- a/gcc/d/dmd/aliasthis.d
+++ b/gcc/d/dmd/aliasthis.d
@@ -23,7 +23,6 @@ import dmd.globals;
 import dmd.identifier;
 import dmd.location;
 import dmd.mtype;
-import dmd.opover;
 import dmd.tokens;
 import dmd.visitor;
 
@@ -38,7 +37,7 @@ extern (C++) final class AliasThis : Dsymbol
     /// Whether this `alias this` is deprecated or not
     bool isDeprecated_;
 
-    extern (D) this(const ref Loc loc, Identifier ident)
+    extern (D) this(const ref Loc loc, Identifier ident) @safe
     {
         super(loc, null);    // it's anonymous (no identifier)
         this.ident = ident;
diff --git a/gcc/d/dmd/arrayop.d b/gcc/d/dmd/arrayop.d
index 908855e271c..d8430733428 100644
--- a/gcc/d/dmd/arrayop.d
+++ b/gcc/d/dmd/arrayop.d
@@ -22,14 +22,12 @@ import dmd.dsymbol;
 import dmd.expression;
 import dmd.expressionsem;
 import dmd.func;
-import dmd.globals;
 import dmd.hdrgen;
 import dmd.id;
 import dmd.identifier;
 import dmd.location;
 import dmd.mtype;
 import dmd.common.outbuffer;
-import dmd.statement;
 import dmd.tokens;
 import dmd.visitor;
 
@@ -194,7 +192,7 @@ private Expressions* buildArrayOp(Scope* sc, Expression e, Objects* tiargs)
         Expressions* args;
 
     public:
-        extern (D) this(Scope* sc, Objects* tiargs) scope
+        extern (D) this(Scope* sc, Objects* tiargs) scope @safe
         {
             this.sc = sc;
             this.tiargs = tiargs;
@@ -276,7 +274,7 @@ bool isArrayOpImplicitCast(TypeDArray tfrom, TypeDArray tto)
 /***********************************************
  * Test if expression is a unary array op.
  */
-bool isUnaArrayOp(EXP op)
+bool isUnaArrayOp(EXP op) @safe
 {
     switch (op)
     {
@@ -292,7 +290,7 @@ bool isUnaArrayOp(EXP op)
 /***********************************************
  * Test if expression is a binary array op.
  */
-bool isBinArrayOp(EXP op)
+bool isBinArrayOp(EXP op) @safe
 {
     switch (op)
     {
@@ -315,7 +313,7 @@ bool isBinArrayOp(EXP op)
 /***********************************************
  * Test if expression is a binary assignment array op.
  */
-bool isBinAssignArrayOp(EXP op)
+bool isBinAssignArrayOp(EXP op) @safe
 {
     switch (op)
     {
diff --git a/gcc/d/dmd/attrib.d b/gcc/d/dmd/attrib.d
index ff4ebe8eaf9..baabe930c68 100644
--- a/gcc/d/dmd/attrib.d
+++ b/gcc/d/dmd/attrib.d
@@ -45,7 +45,6 @@ import dmd.mtype;
 import dmd.objc; // for objc.addSymbols
 import dmd.common.outbuffer;
 import dmd.root.array; // for each
-import dmd.tokens;
 import dmd.visitor;
 
 /***********************************************************
@@ -57,18 +56,18 @@ extern (C++) abstract class AttribDeclaration : Dsymbol
 {
     Dsymbols* decl;     /// Dsymbol's affected by this AttribDeclaration
 
-    extern (D) this(Dsymbols* decl)
+    extern (D) this(Dsymbols* decl) @safe
     {
         this.decl = decl;
     }
 
-    extern (D) this(const ref Loc loc, Dsymbols* decl)
+    extern (D) this(const ref Loc loc, Dsymbols* decl) @safe
     {
         super(loc, null);
         this.decl = decl;
     }
 
-    extern (D) this(const ref Loc loc, Identifier ident, Dsymbols* decl)
+    extern (D) this(const ref Loc loc, Identifier ident, Dsymbols* decl) @safe
     {
         super(loc, ident);
         this.decl = decl;
@@ -228,13 +227,13 @@ extern (C++) class StorageClassDeclaration : AttribDeclaration
 {
     StorageClass stc;
 
-    extern (D) this(StorageClass stc, Dsymbols* decl)
+    extern (D) this(StorageClass stc, Dsymbols* decl) @safe
     {
         super(decl);
         this.stc = stc;
     }
 
-    extern (D) this(const ref Loc loc, StorageClass stc, Dsymbols* decl)
+    extern (D) this(const ref Loc loc, StorageClass stc, Dsymbols* decl) @safe
     {
         super(loc, decl);
         this.stc = stc;
@@ -347,7 +346,7 @@ extern (C++) final class DeprecatedDeclaration : StorageClassDeclaration
     Expression msg;         /// deprecation message
     const(char)* msgstr;    /// cached string representation of msg
 
-    extern (D) this(Expression msg, Dsymbols* decl)
+    extern (D) this(Expression msg, Dsymbols* decl) @safe
     {
         super(STC.deprecated_, decl);
         this.msg = msg;
@@ -402,14 +401,14 @@ extern (C++) final class LinkDeclaration : AttribDeclaration
 {
     LINK linkage; /// either explicitly set or `default_`
 
-    extern (D) this(const ref Loc loc, LINK linkage, Dsymbols* decl)
+    extern (D) this(const ref Loc loc, LINK linkage, Dsymbols* decl) @safe
     {
         super(loc, null, decl);
         //printf("LinkDeclaration(linkage = %d, decl = %p)\n", linkage, decl);
         this.linkage = linkage;
     }
 
-    static LinkDeclaration create(const ref Loc loc, LINK p, Dsymbols* decl)
+    static LinkDeclaration create(const ref Loc loc, LINK p, Dsymbols* decl) @safe
     {
         return new LinkDeclaration(loc, p, decl);
     }
@@ -454,7 +453,7 @@ extern (C++) final class CPPMangleDeclaration : AttribDeclaration
 {
     CPPMANGLE cppmangle;
 
-    extern (D) this(const ref Loc loc, CPPMANGLE cppmangle, Dsymbols* decl)
+    extern (D) this(const ref Loc loc, CPPMANGLE cppmangle, Dsymbols* decl) @safe
     {
         super(loc, null, decl);
         //printf("CPPMangleDeclaration(cppmangle = %d, decl = %p)\n", cppmangle, decl);
@@ -524,19 +523,19 @@ extern (C++) final class CPPNamespaceDeclaration : AttribDeclaration
     /// CTFE-able expression, resolving to `TupleExp` or `StringExp`
     Expression exp;
 
-    extern (D) this(const ref Loc loc, Identifier ident, Dsymbols* decl)
+    extern (D) this(const ref Loc loc, Identifier ident, Dsymbols* decl) @safe
     {
         super(loc, ident, decl);
     }
 
-    extern (D) this(const ref Loc loc, Expression exp, Dsymbols* decl)
+    extern (D) this(const ref Loc loc, Expression exp, Dsymbols* decl) @safe
     {
         super(loc, null, decl);
         this.exp = exp;
     }
 
     extern (D) this(const ref Loc loc, Identifier ident, Expression exp, Dsymbols* decl,
-                    CPPNamespaceDeclaration parent)
+                    CPPNamespaceDeclaration parent) @safe
     {
         super(loc, ident, decl);
         this.exp = exp;
@@ -597,7 +596,7 @@ extern (C++) final class VisibilityDeclaration : AttribDeclaration
      *  visibility = visibility attribute data
      *  decl = declarations which are affected by this visibility attribute
      */
-    extern (D) this(const ref Loc loc, Visibility visibility, Dsymbols* decl)
+    extern (D) this(const ref Loc loc, Visibility visibility, Dsymbols* decl) @safe
     {
         super(loc, null, decl);
         this.visibility = visibility;
@@ -720,13 +719,13 @@ extern (C++) final class AlignDeclaration : AttribDeclaration
         }
     }
 
-    extern (D) this(const ref Loc loc, Expressions* exps, Dsymbols* decl)
+    extern (D) this(const ref Loc loc, Expressions* exps, Dsymbols* decl) @safe
     {
         super(loc, null, decl);
         this.exps = exps;
     }
 
-    extern (D) this(const ref Loc loc, structalign_t salign, Dsymbols* decl)
+    extern (D) this(const ref Loc loc, structalign_t salign, Dsymbols* decl) @safe
     {
         super(loc, null, decl);
         this.salign = salign;
@@ -762,7 +761,7 @@ extern (C++) final class AnonDeclaration : AttribDeclaration
     uint anonstructsize;    /// size of anonymous struct
     uint anonalignsize;     /// size of anonymous struct for alignment purposes
 
-    extern (D) this(const ref Loc loc, bool isunion, Dsymbols* decl)
+    extern (D) this(const ref Loc loc, bool isunion, Dsymbols* decl) @safe
     {
         super(loc, null, decl);
         this.isunion = isunion;
@@ -882,7 +881,7 @@ extern (C++) final class PragmaDeclaration : AttribDeclaration
 {
     Expressions* args;      /// parameters of this pragma
 
-    extern (D) this(const ref Loc loc, Identifier ident, Expressions* args, Dsymbols* decl)
+    extern (D) this(const ref Loc loc, Identifier ident, Expressions* args, Dsymbols* decl) @safe
     {
         super(loc, ident, decl);
         this.args = args;
@@ -928,7 +927,7 @@ extern (C++) class ConditionalDeclaration : AttribDeclaration
     Condition condition;    /// condition deciding whether decl or elsedecl applies
     Dsymbols* elsedecl;     /// array of Dsymbol's for else block
 
-    extern (D) this(const ref Loc loc, Condition condition, Dsymbols* decl, Dsymbols* elsedecl)
+    extern (D) this(const ref Loc loc, Condition condition, Dsymbols* decl, Dsymbols* elsedecl) @safe
     {
         super(loc, null, decl);
         //printf("ConditionalDeclaration::ConditionalDeclaration()\n");
@@ -1006,7 +1005,7 @@ extern (C++) final class StaticIfDeclaration : ConditionalDeclaration
     private bool addisdone = false; /// true if members have been added to scope
     private bool onStack = false;   /// true if a call to `include` is currently active
 
-    extern (D) this(const ref Loc loc, Condition condition, Dsymbols* decl, Dsymbols* elsedecl)
+    extern (D) this(const ref Loc loc, Condition condition, Dsymbols* decl, Dsymbols* elsedecl) @safe
     {
         super(loc, condition, decl, elsedecl);
         //printf("StaticIfDeclaration::StaticIfDeclaration()\n");
@@ -1120,7 +1119,7 @@ extern (C++) final class StaticForeachDeclaration : AttribDeclaration
     bool cached = false;
     Dsymbols* cache = null;
 
-    extern (D) this(StaticForeach sfe, Dsymbols* decl)
+    extern (D) this(StaticForeach sfe, Dsymbols* decl) @safe
     {
         super(sfe.loc, null, decl);
         this.sfe = sfe;
@@ -1251,7 +1250,7 @@ extern(C++) final class ForwardingAttribDeclaration : AttribDeclaration
 {
     ForwardingScopeDsymbol sym = null;
 
-    this(Dsymbols* decl)
+    this(Dsymbols* decl) @safe
     {
         super(decl);
         sym = new ForwardingScopeDsymbol();
@@ -1299,7 +1298,7 @@ extern (C++) final class MixinDeclaration : AttribDeclaration
     ScopeDsymbol scopesym;
     bool compiled;
 
-    extern (D) this(const ref Loc loc, Expressions* exps)
+    extern (D) this(const ref Loc loc, Expressions* exps) @safe
     {
         super(loc, null, null);
         //printf("MixinDeclaration(loc = %d)\n", loc.linnum);
@@ -1348,7 +1347,7 @@ extern (C++) final class UserAttributeDeclaration : AttribDeclaration
 {
     Expressions* atts;
 
-    extern (D) this(Expressions* atts, Dsymbols* decl)
+    extern (D) this(Expressions* atts, Dsymbols* decl) @safe
     {
         super(decl);
         this.atts = atts;
diff --git a/gcc/d/dmd/blockexit.d b/gcc/d/dmd/blockexit.d
index db738b4076c..bdc81f246cd 100644
--- a/gcc/d/dmd/blockexit.d
+++ b/gcc/d/dmd/blockexit.d
@@ -27,7 +27,6 @@ import dmd.location;
 import dmd.mtype;
 import dmd.statement;
 import dmd.tokens;
-import dmd.visitor;
 
 /**
  * BE stands for BlockExit.
diff --git a/gcc/d/dmd/canthrow.d b/gcc/d/dmd/canthrow.d
index 89d5519b5d8..ba13eb084bd 100644
--- a/gcc/d/dmd/canthrow.d
+++ b/gcc/d/dmd/canthrow.d
@@ -26,7 +26,6 @@ import dmd.globals;
 import dmd.init;
 import dmd.mtype;
 import dmd.postordervisitor;
-import dmd.root.rootobject;
 import dmd.tokens;
 import dmd.visitor;
 
@@ -63,7 +62,7 @@ extern (C++) /* CT */ BE canThrow(Expression e, FuncDeclaration func, bool mustN
         CT result;
 
     public:
-        extern (D) this(FuncDeclaration func, bool mustNotThrow) scope
+        extern (D) this(FuncDeclaration func, bool mustNotThrow) scope @safe
         {
             this.func = func;
             this.mustNotThrow = mustNotThrow;
diff --git a/gcc/d/dmd/common/file.d b/gcc/d/dmd/common/file.d
index ae13c41d310..076f357e50b 100644
--- a/gcc/d/dmd/common/file.d
+++ b/gcc/d/dmd/common/file.d
@@ -27,6 +27,14 @@ import dmd.common.string;
 
 nothrow:
 
+version (Windows)
+{
+    import core.sys.windows.winnls : CP_ACP;
+
+    // assume filenames encoded in system default Windows ANSI code page
+    enum CodePage = CP_ACP;
+}
+
 /**
 Encapsulated management of a memory-mapped file.
 
diff --git a/gcc/d/dmd/common/outbuffer.d b/gcc/d/dmd/common/outbuffer.d
index 007d301359c..b8ad7851e4d 100644
--- a/gcc/d/dmd/common/outbuffer.d
+++ b/gcc/d/dmd/common/outbuffer.d
@@ -61,7 +61,7 @@ struct OutBuffer
     /**
     Construct given size.
     */
-    this(size_t initialSize) nothrow
+    this(size_t initialSize) nothrow @safe
     {
         reserve(initialSize);
     }
@@ -527,7 +527,7 @@ struct OutBuffer
      * Returns:
      *  slice of the allocated space to be filled in
      */
-    extern (D) char[] allocate(size_t nbytes) pure nothrow
+    extern (D) char[] allocate(size_t nbytes) pure nothrow @safe
     {
         reserve(nbytes);
         offset += nbytes;
@@ -711,8 +711,14 @@ struct OutBuffer
         return cast(char*)data.ptr;
     }
 
+    // Peek at slice of data without taking ownership
+    extern (D) ubyte[] peekSlice() pure nothrow
+    {
+        return data[0 .. offset];
+    }
+
     // Append terminating null if necessary and take ownership of data
-    extern (C++) char* extractChars() pure nothrow
+    extern (C++) char* extractChars() pure nothrow @safe
     {
         if (!offset || data[offset - 1] != '\0')
             writeByte(0);
diff --git a/gcc/d/dmd/common/string.d b/gcc/d/dmd/common/string.d
index 6de921e3d7a..9453a3474da 100644
--- a/gcc/d/dmd/common/string.d
+++ b/gcc/d/dmd/common/string.d
@@ -135,9 +135,8 @@ but is guaranteed to follow it.
 */
 version(Windows) wchar[] toWStringz(const(char)[] narrow, ref SmallBuffer!wchar buffer) nothrow
 {
-    import core.sys.windows.winnls : CP_ACP, MultiByteToWideChar;
-    // assume filenames encoded in system default Windows ANSI code page
-    enum CodePage = CP_ACP;
+    import core.sys.windows.winnls : MultiByteToWideChar;
+    import dmd.common.file : CodePage;
 
     if (narrow is null)
         return null;
diff --git a/gcc/d/dmd/cond.d b/gcc/d/dmd/cond.d
index 467f9f1a990..360acf590bb 100644
--- a/gcc/d/dmd/cond.d
+++ b/gcc/d/dmd/cond.d
@@ -62,7 +62,7 @@ extern (C++) abstract class Condition : ASTNode
         return DYNCAST.condition;
     }
 
-    extern (D) this(const ref Loc loc)
+    extern (D) this(const ref Loc loc) @safe
     {
         this.loc = loc;
     }
@@ -124,7 +124,7 @@ extern (C++) final class StaticForeach : RootObject
      */
     bool needExpansion = false;
 
-    extern (D) this(const ref Loc loc, ForeachStatement aggrfe, ForeachRangeStatement rangefe)
+    extern (D) this(const ref Loc loc, ForeachStatement aggrfe, ForeachRangeStatement rangefe) @safe
     {
         assert(!!aggrfe ^ !!rangefe);
 
@@ -279,7 +279,7 @@ extern (C++) final class StaticForeach : RootObject
      *     An AST for the expression `Tuple(e)`.
      */
 
-    private extern(D) Expression createTuple(const ref Loc loc, TypeStruct type, Expressions* e)
+    private extern(D) Expression createTuple(const ref Loc loc, TypeStruct type, Expressions* e) @safe
     {   // TODO: move to druntime?
         return new CallExp(loc, new TypeExp(loc, type), e);
     }
@@ -496,7 +496,7 @@ extern (C++) class DVCondition : Condition
     Identifier ident;
     Module mod;
 
-    extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident)
+    extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident) @safe
     {
         super(loc);
         this.mod = mod;
@@ -563,7 +563,7 @@ extern (C++) final class DebugCondition : DVCondition
      *           If `null`, this conditiion will use an integer level.
      *  loc = Location in the source file
      */
-    extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident)
+    extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident) @safe
     {
         super(loc, mod, level, ident);
     }
@@ -637,7 +637,7 @@ extern (C++) final class VersionCondition : DVCondition
      * Returns:
      *   `true` if it is reserved, `false` otherwise
      */
-    extern(D) private static bool isReserved(const(char)[] ident)
+    extern(D) private static bool isReserved(const(char)[] ident) @safe
     {
         // This list doesn't include "D_*" versions, see the last return
         switch (ident)
@@ -840,7 +840,7 @@ extern (C++) final class VersionCondition : DVCondition
      *           If `null`, this conditiion will use an integer level.
      *  loc = Location in the source file
      */
-    extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident)
+    extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident) @safe
     {
         super(loc, mod, level, ident);
     }
@@ -902,7 +902,7 @@ extern (C++) final class StaticIfCondition : Condition
 {
     Expression exp;
 
-    extern (D) this(const ref Loc loc, Expression exp)
+    extern (D) this(const ref Loc loc, Expression exp) @safe
     {
         super(loc);
         this.exp = exp;
diff --git a/gcc/d/dmd/constfold.d b/gcc/d/dmd/constfold.d
index 415606bd704..e5526a1c9aa 100644
--- a/gcc/d/dmd/constfold.d
+++ b/gcc/d/dmd/constfold.d
@@ -52,7 +52,7 @@ private Expression expType(Type type, Expression e)
  * Returns:
  *    true if e is a constant
  */
-int isConst(Expression e)
+int isConst(Expression e) @safe
 {
     //printf("Expression::isConst(): %s\n", e.toChars());
     switch (e.op)
@@ -1286,7 +1286,7 @@ UnionExp Slice(Type type, Expression e1, Expression lwr, Expression upr)
 
 /* Check whether slice `[newlwr .. newupr]` is in the range `[lwr .. upr]`
  */
-bool sliceBoundsCheck(uinteger_t lwr, uinteger_t upr, uinteger_t newlwr, uinteger_t newupr) pure
+bool sliceBoundsCheck(uinteger_t lwr, uinteger_t upr, uinteger_t newlwr, uinteger_t newupr) pure @safe
 {
     assert(lwr <= upr);
     return !(newlwr <= newupr &&
diff --git a/gcc/d/dmd/cppmangle.d b/gcc/d/dmd/cppmangle.d
index ee1340d6342..5d74ec4c91a 100644
--- a/gcc/d/dmd/cppmangle.d
+++ b/gcc/d/dmd/cppmangle.d
@@ -139,7 +139,7 @@ private struct Context
      * Returns:
      *   The previous state of this `Context` object
      */
-    private Context push(lazy RootObject next)
+    private Context push(lazy RootObject next) @safe
     {
         auto r = this.res;
         if (r !is null)
@@ -150,7 +150,7 @@ private struct Context
     /**
      * Reset the context to a previous one, making any adjustment necessary
      */
-    private void pop(ref Context prev)
+    private void pop(ref Context prev) @safe
     {
         this.res = prev.res;
     }
@@ -236,7 +236,7 @@ private final class CppMangleVisitor : Visitor
      * See-Also:
      *  https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangle.seq-id
      */
-    private void writeSequenceFromIndex(size_t idx)
+    private void writeSequenceFromIndex(size_t idx) @safe
     {
         if (idx)
         {
@@ -1597,7 +1597,7 @@ private final class CppMangleVisitor : Visitor
      *   or `params.length` if there wasn't any match.
      */
     private static size_t templateParamIndex(
-        const ref Identifier ident, TemplateParameters* params)
+        const ref Identifier ident, TemplateParameters* params) @safe
     {
         foreach (idx, param; *params)
             if (param.ident == ident)
@@ -2131,7 +2131,7 @@ private void visitObject(V : Visitor)(RootObject o, V this_)
 }
 
 /// Helper function to safely get a type out of a `RootObject`
-private Type asType(RootObject o)
+private Type asType(RootObject o) @safe
 {
     if (Type ta = isType(o))
         return ta;
@@ -2143,7 +2143,7 @@ private Type asType(RootObject o)
 }
 
 /// Helper function to safely get a `FuncDeclaration` out of a `RootObject`
-private FuncDeclaration asFuncDecl(RootObject o)
+private FuncDeclaration asFuncDecl(RootObject o) @safe
 {
     Dsymbol d = isDsymbol(o);
     assert(d !is null);
@@ -2177,7 +2177,7 @@ private extern(C++) final class ComponentVisitor : Visitor
     /// Set to the result of the comparison
     private bool result;
 
-    public this(RootObject base)
+    public this(RootObject base) @safe
     {
         switch (base.dyncast())
         {
@@ -2353,7 +2353,7 @@ private bool isNamespaceEqual (CPPNamespaceDeclaration a, Nspace b, size_t idx =
 
 /// Returns:
 ///   Whether  two `CPPNamespaceDeclaration` are equals
-private bool isNamespaceEqual (CPPNamespaceDeclaration a, CPPNamespaceDeclaration b)
+private bool isNamespaceEqual (CPPNamespaceDeclaration a, CPPNamespaceDeclaration b) @safe
 {
     if (a is null || b is null)
         return false;
@@ -2558,7 +2558,7 @@ void leftOver(TypeFunction tf, const(Array!StringExp)* previous, Array!StringExp
         private const(Array!StringExp)* ignore;
 
         ///
-        public this(const(Array!StringExp)* previous, Array!StringExp* toWrite)
+        public this(const(Array!StringExp)* previous, Array!StringExp* toWrite) @safe
         {
             this.ignore = previous;
             this.toWrite = toWrite;
diff --git a/gcc/d/dmd/ctfeexpr.d b/gcc/d/dmd/ctfeexpr.d
index 289ebeb81ca..d355538e97c 100644
--- a/gcc/d/dmd/ctfeexpr.d
+++ b/gcc/d/dmd/ctfeexpr.d
@@ -45,7 +45,7 @@ extern (C++) final class ClassReferenceExp : Expression
 {
     StructLiteralExp value;
 
-    extern (D) this(const ref Loc loc, StructLiteralExp lit, Type type)
+    extern (D) this(const ref Loc loc, StructLiteralExp lit, Type type) @safe
     {
         super(loc, EXP.classReference);
         assert(lit && lit.sd && lit.sd.isClassDeclaration());
@@ -112,7 +112,7 @@ extern (C++) final class ClassReferenceExp : Expression
  * Returns:
  *    index of the field, or -1 if not found
  */
-int findFieldIndexByName(const StructDeclaration sd, const VarDeclaration v) pure
+int findFieldIndexByName(const StructDeclaration sd, const VarDeclaration v) pure @safe
 {
     foreach (i, field; sd.fields)
     {
@@ -130,7 +130,7 @@ extern (C++) final class ThrownExceptionExp : Expression
 {
     ClassReferenceExp thrown;   // the thing being tossed
 
-    extern (D) this(const ref Loc loc, ClassReferenceExp victim)
+    extern (D) this(const ref Loc loc, ClassReferenceExp victim) @safe
     {
         super(loc, EXP.thrownException);
         this.thrown = victim;
@@ -205,19 +205,19 @@ extern (C++) final class CTFEExp : Expression
      */
     extern (D) __gshared CTFEExp showcontext;
 
-    extern (D) static bool isCantExp(const Expression e)
+    extern (D) static bool isCantExp(const Expression e) @safe
     {
         return e && e.op == EXP.cantExpression;
     }
 
-    extern (D) static bool isGotoExp(const Expression e)
+    extern (D) static bool isGotoExp(const Expression e) @safe
     {
         return e && e.op == EXP.goto_;
     }
 }
 
 // True if 'e' is CTFEExp::cantexp, or an exception
-bool exceptionOrCantInterpret(const Expression e)
+bool exceptionOrCantInterpret(const Expression e) @safe
 {
     return e && (e.op == EXP.cantExpression || e.op == EXP.thrownException || e.op == EXP.showCtfeContext);
 }
@@ -1068,25 +1068,25 @@ private bool numCmp(N)(EXP op, N n1, N n2)
 }
 
 /// Returns cmp OP 0; where OP is ==, !=, <, >=, etc. Result is 0 or 1
-bool specificCmp(EXP op, int rawCmp)
+bool specificCmp(EXP op, int rawCmp) @safe
 {
     return numCmp!int(op, rawCmp, 0);
 }
 
 /// Returns e1 OP e2; where OP is ==, !=, <, >=, etc. Result is 0 or 1
-bool intUnsignedCmp(EXP op, dinteger_t n1, dinteger_t n2)
+bool intUnsignedCmp(EXP op, dinteger_t n1, dinteger_t n2) @safe
 {
     return numCmp!dinteger_t(op, n1, n2);
 }
 
 /// Returns e1 OP e2; where OP is ==, !=, <, >=, etc. Result is 0 or 1
-bool intSignedCmp(EXP op, sinteger_t n1, sinteger_t n2)
+bool intSignedCmp(EXP op, sinteger_t n1, sinteger_t n2) @safe
 {
     return numCmp!sinteger_t(op, n1, n2);
 }
 
 /// Returns e1 OP e2; where OP is ==, !=, <, >=, etc. Result is 0 or 1
-bool realCmp(EXP op, real_t r1, real_t r2)
+bool realCmp(EXP op, real_t r1, real_t r2) @safe
 {
     // Don't rely on compiler, handle NAN arguments separately
     if (CTFloat.isNaN(r1) || CTFloat.isNaN(r2)) // if unordered
@@ -1176,7 +1176,7 @@ private int ctfeCmpArrays(const ref Loc loc, Expression e1, Expression e2, uinte
 /* Given a delegate expression e, return .funcptr.
  * If e is NullExp, return NULL.
  */
-private FuncDeclaration funcptrOf(Expression e)
+private FuncDeclaration funcptrOf(Expression e) @safe
 {
     assert(e.type.ty == Tdelegate);
     if (auto de = e.isDelegateExp())
@@ -1187,7 +1187,7 @@ private FuncDeclaration funcptrOf(Expression e)
     return null;
 }
 
-private bool isArray(const Expression e)
+private bool isArray(const Expression e) @safe
 {
     return e.op == EXP.arrayLiteral || e.op == EXP.string_ || e.op == EXP.slice || e.op == EXP.null_;
 }
diff --git a/gcc/d/dmd/ctorflow.d b/gcc/d/dmd/ctorflow.d
index a3953af6ce8..128c698ab87 100644
--- a/gcc/d/dmd/ctorflow.d
+++ b/gcc/d/dmd/ctorflow.d
@@ -71,7 +71,7 @@ struct CtorFlow
      * Params:
      *  csx = bits to set
      */
-    void orCSX(CSX csx) nothrow pure
+    void orCSX(CSX csx) nothrow pure @safe
     {
         callSuper |= csx;
         foreach (ref u; fieldinit)
@@ -83,7 +83,7 @@ struct CtorFlow
      * Params:
      *  ctorflow = bits to OR in
      */
-    void OR(const ref CtorFlow ctorflow) pure nothrow
+    void OR(const ref CtorFlow ctorflow) pure nothrow @safe
     {
         callSuper |= ctorflow.callSuper;
         if (fieldinit.length && ctorflow.fieldinit.length)
@@ -109,7 +109,7 @@ struct CtorFlow
  * Returns:
  *      false means one of the paths skips construction
  */
-bool mergeCallSuper(ref CSX a, const CSX b) pure nothrow
+bool mergeCallSuper(ref CSX a, const CSX b) pure nothrow @safe
 {
     // This does a primitive flow analysis to support the restrictions
     // regarding when and how constructors can appear.
@@ -172,7 +172,7 @@ bool mergeCallSuper(ref CSX a, const CSX b) pure nothrow
  * Returns:
  *      false means either `a` or `b` skips initialization
  */
-bool mergeFieldInit(ref CSX a, const CSX b) pure nothrow
+bool mergeFieldInit(ref CSX a, const CSX b) pure nothrow @safe
 {
     if (b == a)
         return true;
diff --git a/gcc/d/dmd/dclass.d b/gcc/d/dmd/dclass.d
index 1b8e8ef1880..20cb82e1a36 100644
--- a/gcc/d/dmd/dclass.d
+++ b/gcc/d/dmd/dclass.d
@@ -1130,7 +1130,7 @@ extern (C++) final class InterfaceDeclaration : ClassDeclaration
  * Returns:
  *    true if the `bc` implements `id`, false otherwise
  **/
-private bool baseClassImplementsInterface(InterfaceDeclaration id, BaseClass* bc, int* poffset) pure nothrow @nogc
+private bool baseClassImplementsInterface(InterfaceDeclaration id, BaseClass* bc, int* poffset) pure nothrow @nogc @safe
 {
     //printf("%s.InterfaceDeclaration.isBaseOf(bc = '%s')\n", id.toChars(), bc.sym.toChars());
     for (size_t j = 0; j < bc.baseInterfaces.length; j++)
diff --git a/gcc/d/dmd/declaration.d b/gcc/d/dmd/declaration.d
index 5559b93eb20..8a91a802dae 100644
--- a/gcc/d/dmd/declaration.d
+++ b/gcc/d/dmd/declaration.d
@@ -188,6 +188,15 @@ bool modifyFieldVar(Loc loc, Scope* sc, VarDeclaration var, Expression e1)
                     MODtoChars(var.type.mod), var.kind(), var.toChars());
                 errorSupplemental(loc, "Use `shared static this` instead.");
             }
+            else if (fd.isStaticCtorDeclaration() && !fd.isSharedStaticCtorDeclaration() &&
+                    var.type.isConst())
+            {
+                // @@@DEPRECATED_2.116@@@
+                // Turn this into an error, merging with the branch above
+                .deprecation(loc, "%s %s `%s` initialization is not allowed in `static this`",
+                    MODtoChars(var.type.mod), var.kind(), var.toChars());
+                deprecationSupplemental(loc, "Use `shared static this` instead.");
+            }
             return result;
         }
         else
@@ -242,13 +251,13 @@ extern (C++) abstract class Declaration : Dsymbol
     // overridden symbol with pragma(mangle, "...")
     const(char)[] mangleOverride;
 
-    final extern (D) this(Identifier ident)
+    final extern (D) this(Identifier ident) @safe
     {
         super(ident);
         visibility = Visibility(Visibility.Kind.undefined);
     }
 
-    final extern (D) this(const ref Loc loc, Identifier ident)
+    final extern (D) this(const ref Loc loc, Identifier ident) @safe
     {
         super(loc, ident);
         visibility = Visibility(Visibility.Kind.undefined);
@@ -586,7 +595,7 @@ extern (C++) final class TupleDeclaration : Declaration
     bool isexp;             // true: expression tuple
     bool building;          // it's growing in AliasAssign semantic
 
-    extern (D) this(const ref Loc loc, Identifier ident, Objects* objects)
+    extern (D) this(const ref Loc loc, Identifier ident, Objects* objects) @safe
     {
         super(loc, ident);
         this.objects = objects;
@@ -617,7 +626,7 @@ extern (C++) final class TupleDeclaration : Declaration
             for (size_t i = 0; i < objects.length; i++)
             {
                 RootObject o = (*objects)[i];
-                if (o.dyncast() != DYNCAST.type)
+                if (!o.isType())
                 {
                     //printf("\tnot[%d], %p, %d\n", i, o, o.dyncast());
                     return null;
@@ -737,7 +746,7 @@ extern (C++) final class AliasDeclaration : Declaration
     Dsymbol overnext;   // next in overload list
     Dsymbol _import;    // !=null if unresolved internal alias for selective import
 
-    extern (D) this(const ref Loc loc, Identifier ident, Type type)
+    extern (D) this(const ref Loc loc, Identifier ident, Type type) @safe
     {
         super(loc, ident);
         //printf("AliasDeclaration(id = '%s', type = %p)\n", ident.toChars(), type);
@@ -746,7 +755,7 @@ extern (C++) final class AliasDeclaration : Declaration
         assert(type);
     }
 
-    extern (D) this(const ref Loc loc, Identifier ident, Dsymbol s)
+    extern (D) this(const ref Loc loc, Identifier ident, Dsymbol s) @safe
     {
         super(loc, ident);
         //printf("AliasDeclaration(id = '%s', s = %p)\n", ident.toChars(), s);
@@ -755,7 +764,7 @@ extern (C++) final class AliasDeclaration : Declaration
         assert(s);
     }
 
-    static AliasDeclaration create(const ref Loc loc, Identifier id, Type type)
+    static AliasDeclaration create(const ref Loc loc, Identifier id, Type type) @safe
     {
         return new AliasDeclaration(loc, id, type);
     }
@@ -1036,7 +1045,7 @@ extern (C++) final class OverDeclaration : Declaration
     Dsymbol overnext;   // next in overload list
     Dsymbol aliassym;
 
-    extern (D) this(Identifier ident, Dsymbol s)
+    extern (D) this(Identifier ident, Dsymbol s) @safe
     {
         super(ident);
         this.aliassym = s;
@@ -1158,10 +1167,11 @@ extern (C++) class VarDeclaration : Declaration
             bool inClosure;         /// is inserted into a GC allocated closure
             bool inAlignSection;    /// is inserted into an aligned section on stack
         }
+        bool systemInferred;    /// @system was inferred from initializer
     }
 
     import dmd.common.bitfields : generateBitFields;
-    mixin(generateBitFields!(BitFields, ushort));
+    mixin(generateBitFields!(BitFields, uint));
 
     byte canassign;                 // it can be assigned to
     ubyte isdataseg;                // private data for isDataseg 0 unset, 1 true, 2 false
@@ -2003,7 +2013,7 @@ extern (C++) final class SymbolDeclaration : Declaration
 {
     AggregateDeclaration dsym;
 
-    extern (D) this(const ref Loc loc, AggregateDeclaration dsym)
+    extern (D) this(const ref Loc loc, AggregateDeclaration dsym) @safe
     {
         super(loc, dsym.ident);
         this.dsym = dsym;
diff --git a/gcc/d/dmd/declaration.h b/gcc/d/dmd/declaration.h
index 197091e1d89..71f2baa525f 100644
--- a/gcc/d/dmd/declaration.h
+++ b/gcc/d/dmd/declaration.h
@@ -244,7 +244,7 @@ public:
     // The index of this variable on the CTFE stack, ~0u if not allocated
     unsigned ctfeAdrOnStack;
 private:
-    uint16_t bitFields;
+    uint32_t bitFields;
 public:
     int8_t canassign; // // it can be assigned to
     uint8_t isdataseg; // private data for isDataseg
@@ -278,6 +278,8 @@ public:
     bool inAlignSection() const; // is inserted into aligned section on stack
     bool inAlignSection(bool v);
 #endif
+    bool systemInferred() const;
+    bool systemInferred(bool v);
     static VarDeclaration *create(const Loc &loc, Type *t, Identifier *id, Initializer *init, StorageClass storage_class = STCundefined);
     VarDeclaration *syntaxCopy(Dsymbol *) override;
     void setFieldOffset(AggregateDeclaration *ad, FieldState& fieldState, bool isunion) override final;
diff --git a/gcc/d/dmd/delegatize.d b/gcc/d/dmd/delegatize.d
index b135bfacbf9..559f103908d 100644
--- a/gcc/d/dmd/delegatize.d
+++ b/gcc/d/dmd/delegatize.d
@@ -109,7 +109,7 @@ private void lambdaSetParent(Expression e, FuncDeclaration fd)
         }
 
     public:
-        extern (D) this(FuncDeclaration fd) scope
+        extern (D) this(FuncDeclaration fd) scope @safe
         {
             this.fd = fd;
         }
@@ -205,7 +205,7 @@ bool lambdaCheckForNestedRef(Expression e, Scope* sc)
         Scope* sc;
         bool result;
 
-        extern (D) this(Scope* sc) scope
+        extern (D) this(Scope* sc) scope @safe
         {
             this.sc = sc;
         }
diff --git a/gcc/d/dmd/dinterpret.d b/gcc/d/dmd/dinterpret.d
index cb74a079cd4..59483511f6d 100644
--- a/gcc/d/dmd/dinterpret.d
+++ b/gcc/d/dmd/dinterpret.d
@@ -280,19 +280,19 @@ private:
     Expression localThis;       // value of 'this', or NULL if none
 
 public:
-    size_t stackPointer()
+    size_t stackPointer() @safe
     {
         return values.length;
     }
 
     // The current value of 'this', or NULL if none
-    Expression getThis()
+    Expression getThis() @safe
     {
         return localThis;
     }
 
     // Largest number of stack positions we've used
-    size_t maxStackUsage()
+    size_t maxStackUsage() @safe
     {
         return maxStackPointer;
     }
@@ -1646,7 +1646,7 @@ public:
     Expression result;
     UnionExp* pue;              // storage for `result`
 
-    extern (D) this(UnionExp* pue, InterState* istate, CTFEGoal goal) scope
+    extern (D) this(UnionExp* pue, InterState* istate, CTFEGoal goal) scope @safe
     {
         this.pue = pue;
         this.istate = istate;
@@ -3246,7 +3246,7 @@ public:
      */
     // Returns the variable which is eventually modified, or NULL if an rvalue.
     // thisval is the current value of 'this'.
-    static VarDeclaration findParentVar(Expression e)
+    static VarDeclaration findParentVar(Expression e) @safe
     {
         for (;;)
         {
@@ -6105,7 +6105,10 @@ public:
                 result = interpret(&ue, e.msg, istate);
                 if (exceptionOrCant(result))
                     return;
-                e.error("`%s`", result.toChars());
+                if (StringExp se = result.isStringExp())
+                    e.error("%s", se.toStringz().ptr);
+                else
+                    e.error("%s", result.toChars());
             }
             else
                 e.error("`%s` failed", e.toChars());
@@ -7703,7 +7706,7 @@ private void removeHookTraceImpl(ref CallExp ce, ref FuncDeclaration fd)
     // Get the Hook from the second template parameter
     TemplateInstance templateInstance = fd.parent.isTemplateInstance;
     RootObject hook = (*templateInstance.tiargs)[1];
-    assert(hook.dyncast() == DYNCAST.dsymbol, "Expected _d_HookTraceImpl's second template parameter to be an alias to the hook!");
+    assert(hook.isDsymbol(), "Expected _d_HookTraceImpl's second template parameter to be an alias to the hook!");
     fd = (cast(Dsymbol)hook).isFuncDeclaration;
 
     // Remove the first three trace parameters
diff --git a/gcc/d/dmd/dmangle.d b/gcc/d/dmd/dmangle.d
index ad1e8165668..9b723089712 100644
--- a/gcc/d/dmd/dmangle.d
+++ b/gcc/d/dmd/dmangle.d
@@ -25,14 +25,14 @@ extern (C++) const(char)* mangleExact(FuncDeclaration fd)
     {
         OutBuffer buf;
         auto backref = Backref(null);
-        scope Mangler v = new Mangler(&buf, &backref);
+        scope Mangler v = new Mangler(buf, &backref);
         v.mangleExact(fd);
         fd.mangleString = buf.extractChars();
     }
     return fd.mangleString;
 }
 
-extern (C++) void mangleToBuffer(Type t, OutBuffer* buf)
+extern (C++) void mangleToBuffer(Type t, ref OutBuffer buf)
 {
     //printf("mangleToBuffer t()\n");
     if (t.deco)
@@ -45,7 +45,7 @@ extern (C++) void mangleToBuffer(Type t, OutBuffer* buf)
     }
 }
 
-extern (C++) void mangleToBuffer(Expression e, OutBuffer* buf)
+extern (C++) void mangleToBuffer(Expression e, ref OutBuffer buf)
 {
     //printf("mangleToBuffer e()\n");
     auto backref = Backref(null);
@@ -53,7 +53,7 @@ extern (C++) void mangleToBuffer(Expression e, OutBuffer* buf)
     e.accept(v);
 }
 
-extern (C++) void mangleToBuffer(Dsymbol s, OutBuffer* buf)
+extern (C++) void mangleToBuffer(Dsymbol s, ref OutBuffer buf)
 {
     //printf("mangleToBuffer s(%s)\n", s.toChars());
     auto backref = Backref(null);
@@ -61,7 +61,7 @@ extern (C++) void mangleToBuffer(Dsymbol s, OutBuffer* buf)
     s.accept(v);
 }
 
-extern (C++) void mangleToBuffer(TemplateInstance ti, OutBuffer* buf)
+extern (C++) void mangleToBuffer(TemplateInstance ti, ref OutBuffer buf)
 {
     //printf("mangleToBuffer ti()\n");
     auto backref = Backref(null);
@@ -249,7 +249,7 @@ unittest
  *      buf = buffer to append mangling to
  *      backref = state of back references (updated)
  */
-void mangleType(Type t, ubyte modMask, OutBuffer* buf, ref Backref backref)
+void mangleType(Type t, ubyte modMask, ref OutBuffer buf, ref Backref backref)
 {
     void visitWithMask(Type t, ubyte modMask)
     {
@@ -395,7 +395,7 @@ void mangleType(Type t, ubyte modMask, OutBuffer* buf, ref Backref backref)
 
 /*************************************************************
  */
-void mangleFuncType(TypeFunction t, TypeFunction ta, ubyte modMask, Type tret, OutBuffer* buf, ref Backref backref)
+void mangleFuncType(TypeFunction t, TypeFunction ta, ubyte modMask, Type tret, ref OutBuffer buf, ref Backref backref)
 {
     //printf("mangleFuncType() %s\n", t.toChars());
     if (t.inuse && tret)
@@ -485,7 +485,7 @@ void mangleFuncType(TypeFunction t, TypeFunction ta, ubyte modMask, Type tret, O
 
 /*************************************************************
  */
-void mangleParameter(Parameter p, OutBuffer* buf, ref Backref backref)
+void mangleParameter(Parameter p, ref OutBuffer buf, ref Backref backref)
 {
     // https://dlang.org/spec/abi.html#Parameter
 
@@ -564,9 +564,9 @@ public:
     OutBuffer* buf;
     Backref* backref;
 
-    extern (D) this(OutBuffer* buf, Backref* backref)
+    extern (D) this(ref OutBuffer buf, Backref* backref) @trusted
     {
-        this.buf = buf;
+        this.buf = &buf;
         this.backref = backref;
     }
 
@@ -577,8 +577,8 @@ public:
 
     void mangleIdentifier(Identifier id, Dsymbol s)
     {
-        if (!backref.addRefToIdentifier(buf, id))
-            toBuffer(buf, id.toString(), s);
+        if (!backref.addRefToIdentifier(*buf, id))
+            toBuffer(*buf, id.toString(), s);
     }
 
     ////////////////////////////////////////////////////////////////////////////
@@ -593,7 +593,7 @@ public:
         }
         else if (sthis.type)
         {
-            mangleType(sthis.type, 0, buf, *backref);
+            mangleType(sthis.type, 0, *buf, *backref);
         }
         else
             assert(0);
@@ -627,7 +627,7 @@ public:
                 buf.writeByte('0');
 
             if (localNum)
-                writeLocalParent(buf, localNum);
+                writeLocalParent(*buf, localNum);
         }
     }
 
@@ -651,11 +651,11 @@ public:
         {
             TypeFunction tf = fd.type.isTypeFunction();
             TypeFunction tfo = fd.originalType.isTypeFunction();
-            mangleFuncType(tf, tfo, 0, null, buf, *backref);
+            mangleFuncType(tf, tfo, 0, null, *buf, *backref);
         }
         else
         {
-            mangleType(fd.type, 0, buf, *backref);
+            mangleType(fd.type, 0, *buf, *backref);
         }
     }
 
@@ -856,7 +856,7 @@ public:
             if (ta)
             {
                 buf.writeByte('T');
-                mangleType(ta, 0, buf, *backref);
+                mangleType(ta, 0, *buf, *backref);
             }
             else if (ea)
             {
@@ -899,7 +899,7 @@ public:
 
                 /* Use type mangling that matches what it would be for a function parameter
                 */
-                mangleType(ea.type, 0, buf, *backref);
+                mangleType(ea.type, 0, *buf, *backref);
                 ea.accept(this);
             }
             else if (sa)
@@ -915,13 +915,13 @@ public:
                     if (d.mangleOverride)
                     {
                         buf.writeByte('X');
-                        toBuffer(buf, d.mangleOverride, d);
+                        toBuffer(*buf, d.mangleOverride, d);
                         continue;
                     }
                     if (const id = externallyMangledIdentifier(d))
                     {
                         buf.writeByte('X');
-                        toBuffer(buf, id, d);
+                        toBuffer(*buf, id, d);
                         continue;
                     }
                     if (!d.type || !d.type.deco)
@@ -975,7 +975,7 @@ public:
         if (s.ident)
             mangleIdentifier(s.ident, s);
         else
-            toBuffer(buf, s.toString(), s);
+            toBuffer(*buf, s.toString(), s);
         //printf("Dsymbol.mangle() %s = %s\n", s.toChars(), id);
     }
 
@@ -1003,15 +1003,15 @@ public:
     override void visit(RealExp e)
     {
         buf.writeByte('e');
-        realToMangleBuffer(buf, e.value);
+        realToMangleBuffer(*buf, e.value);
     }
 
     override void visit(ComplexExp e)
     {
         buf.writeByte('c');
-        realToMangleBuffer(buf, e.toReal());
+        realToMangleBuffer(*buf, e.toReal());
         buf.writeByte('c'); // separate the two
-        realToMangleBuffer(buf, e.toImaginary());
+        realToMangleBuffer(*buf, e.toImaginary());
     }
 
     override void visit(NullExp e)
@@ -1145,7 +1145,7 @@ private struct Backref
     *  true if the type was found. A back reference has been encoded.
     *  false if the type was not found. The current position is saved for later back references.
     */
-    bool addRefToType(OutBuffer* buf, Type t)
+    bool addRefToType(ref OutBuffer buf, Type t)
     {
         if (t.isTypeBasic())
             return false;
@@ -1184,14 +1184,14 @@ private struct Backref
     *  true if the identifier was found. A back reference has been encoded.
     *  false if the identifier was not found. The current position is saved for later back references.
     */
-    bool addRefToIdentifier(OutBuffer* buf, Identifier id)
+    bool addRefToIdentifier(ref OutBuffer buf, Identifier id)
     {
         return backrefImpl(buf, idents, id);
     }
 
   private:
 
-    extern(D) bool backrefImpl(T)(OutBuffer* buf, ref AssocArray!(T, size_t) aa, T key)
+    extern(D) bool backrefImpl(T)(ref OutBuffer buf, ref AssocArray!(T, size_t) aa, T key)
     {
         auto p = aa.getLvalue(key);
         if (*p)
@@ -1214,7 +1214,7 @@ private struct Backref
  * Mangle basic type ty to buf.
  */
 
-private void tyToDecoBuffer(OutBuffer* buf, int ty)
+private void tyToDecoBuffer(ref OutBuffer buf, int ty) @safe
 {
     const c = mangleChar[ty];
     buf.writeByte(c);
@@ -1225,7 +1225,7 @@ private void tyToDecoBuffer(OutBuffer* buf, int ty)
 /*********************************
  * Mangling for mod.
  */
-private void MODtoDecoBuffer(OutBuffer* buf, MOD mod)
+private void MODtoDecoBuffer(ref OutBuffer buf, MOD mod) @safe
 {
     switch (mod)
     {
@@ -1274,7 +1274,7 @@ private void MODtoDecoBuffer(OutBuffer* buf, MOD mod)
  *  pos           = relative position to encode
  */
 private
-void writeBackRef(OutBuffer* buf, size_t pos)
+void writeBackRef(ref OutBuffer buf, size_t pos) @safe
 {
     buf.writeByte('Q');
     enum base = 26;
@@ -1296,7 +1296,7 @@ void writeBackRef(OutBuffer* buf, size_t pos)
  * Write length prefixed string to buf.
  */
 private
-extern (D) void toBuffer(OutBuffer* buf, const(char)[] id, Dsymbol s)
+extern (D) void toBuffer(ref OutBuffer buf, const(char)[] id, Dsymbol s)
 {
     const len = id.length;
     if (buf.length + len >= 8 * 1024 * 1024) // 8 megs ought be enough for anyone
@@ -1321,7 +1321,7 @@ extern (D) void toBuffer(OutBuffer* buf, const(char)[] id, Dsymbol s)
  *      localNum = local symbol number
  */
 private
-void writeLocalParent(OutBuffer* buf, uint localNum)
+void writeLocalParent(ref OutBuffer buf, uint localNum)
 {
     uint ndigits = 1;
     auto n = localNum;
@@ -1340,7 +1340,7 @@ void writeLocalParent(OutBuffer* buf, uint localNum)
  *      value = real to write
  */
 private
-void realToMangleBuffer(OutBuffer* buf, real_t value)
+void realToMangleBuffer(ref OutBuffer buf, real_t value)
 {
     /* Rely on %A to get portable mangling.
      * Must munge result to get only identifier characters.
diff --git a/gcc/d/dmd/dmodule.d b/gcc/d/dmd/dmodule.d
index f00dec7a4e3..4a2e15c981b 100644
--- a/gcc/d/dmd/dmodule.d
+++ b/gcc/d/dmd/dmodule.d
@@ -948,7 +948,7 @@ extern (C++) final class Module : Package
          * gets imported, it is unaffected by context.
          * Ignore prevsc.
          */
-        Scope* sc = Scope.createGlobal(this); // create root scope
+        Scope* sc = Scope.createGlobal(this, global.errorSink); // create root scope
 
         if (md && md.msg)
             md.msg = semanticString(sc, md.msg, "deprecation message");
@@ -1380,7 +1380,7 @@ extern (C++) struct ModuleDeclaration
     bool isdeprecated;      // if it is a deprecated module
     Expression msg;
 
-    extern (D) this(const ref Loc loc, Identifier[] packages, Identifier id, Expression msg, bool isdeprecated)
+    extern (D) this(const ref Loc loc, Identifier[] packages, Identifier id, Expression msg, bool isdeprecated) @safe
     {
         this.loc = loc;
         this.packages = packages;
@@ -1389,7 +1389,7 @@ extern (C++) struct ModuleDeclaration
         this.isdeprecated = isdeprecated;
     }
 
-    extern (C++) const(char)* toChars() const
+    extern (C++) const(char)* toChars() const @safe
     {
         OutBuffer buf;
         foreach (pid; packages)
diff --git a/gcc/d/dmd/doc.d b/gcc/d/dmd/doc.d
index 3e60dc4f9d8..887fd6c696c 100644
--- a/gcc/d/dmd/doc.d
+++ b/gcc/d/dmd/doc.d
@@ -34,7 +34,7 @@ import dmd.dstruct;
 import dmd.dsymbol;
 import dmd.dsymbolsem;
 import dmd.dtemplate;
-import dmd.errors;
+import dmd.errorsink;
 import dmd.func;
 import dmd.globals;
 import dmd.hdrgen;
@@ -62,7 +62,7 @@ struct Escape
     /***************************************
      * Find character string to replace c with.
      */
-    const(char)[] escapeChar(char c)
+    const(char)[] escapeChar(char c) @safe
     {
         version (all)
         {
@@ -140,7 +140,7 @@ private class Section
             size_t o = buf.length;
             foreach (char c; name)
                 buf.writeByte((c == '_') ? ' ' : c);
-            escapeStrayParenthesis(loc, buf, o, false);
+            escapeStrayParenthesis(loc, buf, o, false, sc.eSink);
             buf.writestring(")");
         }
         else
@@ -150,7 +150,7 @@ private class Section
     L1:
         size_t o = buf.length;
         buf.write(body_);
-        escapeStrayParenthesis(loc, buf, o, true);
+        escapeStrayParenthesis(loc, buf, o, true, sc.eSink);
         highlightText(sc, a, loc, *buf, o);
         buf.writestring(")");
     }
@@ -252,11 +252,11 @@ private final class ParamSection : Section
                             }
                             else if (!fparam)
                             {
-                                warning(s.loc, "Ddoc: function declaration has no parameter '%.*s'", cast(int)namelen, namestart);
+                                sc.eSink.warning(s.loc, "Ddoc: function declaration has no parameter '%.*s'", cast(int)namelen, namestart);
                             }
                             buf.write(namestart[0 .. namelen]);
                         }
-                        escapeStrayParenthesis(loc, buf, o, true);
+                        escapeStrayParenthesis(loc, buf, o, true, sc.eSink);
                         highlightCode(sc, a, *buf, o);
                     }
                     buf.writestring(")");
@@ -264,7 +264,7 @@ private final class ParamSection : Section
                     {
                         size_t o = buf.length;
                         buf.write(textstart[0 .. textlen]);
-                        escapeStrayParenthesis(loc, buf, o, true);
+                        escapeStrayParenthesis(loc, buf, o, true, sc.eSink);
                         highlightText(sc, a, loc, *buf, o);
                     }
                     buf.writestring(")");
@@ -303,12 +303,12 @@ private final class ParamSection : Section
                             cast(int)(tf.parameterList.varargs == VarArg.variadic);
             if (pcount != paramcount)
             {
-                warning(s.loc, "Ddoc: parameter count mismatch, expected %llu, got %llu",
+                sc.eSink.warning(s.loc, "Ddoc: parameter count mismatch, expected %llu, got %llu",
                         cast(ulong) pcount, cast(ulong) paramcount);
                 if (paramcount == 0)
                 {
                     // Chances are someone messed up the format
-                    warningSupplemental(s.loc, "Note that the format is `param = description`");
+                    sc.eSink.warningSupplemental(s.loc, "Note that the format is `param = description`");
                 }
             }
         }
@@ -355,7 +355,7 @@ private Dsymbol getEponymousMember(TemplateDeclaration td) @safe
     return null;
 }
 
-private TemplateDeclaration getEponymousParent(Dsymbol s)
+private TemplateDeclaration getEponymousParent(Dsymbol s) @safe
 {
     if (!s.parent)
         return null;
@@ -371,7 +371,7 @@ private immutable ddoc_decl_dd_e = ")\n";
 
 /****************************************************
  */
-extern(C++) void gendocfile(Module m)
+extern(C++) void gendocfile(Module m, ErrorSink eSink)
 {
     __gshared OutBuffer mbuf;
     __gshared int mbuf_done;
@@ -397,7 +397,7 @@ extern(C++) void gendocfile(Module m)
         }
     }
     DocComment.parseMacros(m.escapetable, m.macrotable, mbuf[]);
-    Scope* sc = Scope.createGlobal(m); // create root scope
+    Scope* sc = Scope.createGlobal(m, eSink); // create root scope
     DocComment* dc = DocComment.parse(m, m.comment);
     dc.pmacrotable = &m.macrotable;
     dc.escapetable = m.escapetable;
@@ -460,7 +460,7 @@ extern(C++) void gendocfile(Module m)
 
     const success = m.macrotable.expand(buf2, 0, end, null, global.recursionLimit);
     if (!success)
-        error(Loc.initial, "DDoc macro expansion limit exceeded; more than %d expansions.", global.recursionLimit);
+        eSink.error(Loc.initial, "DDoc macro expansion limit exceeded; more than %d expansions.", global.recursionLimit);
 
     version (all)
     {
@@ -568,7 +568,7 @@ void escapeDdocString(OutBuffer* buf, size_t start)
  *    directly preceeded by a backslash with $(LPAREN) or $(RPAREN) instead of
  *    counting them as stray parentheses
  */
-private void escapeStrayParenthesis(Loc loc, OutBuffer* buf, size_t start, bool respectBackslashEscapes)
+private void escapeStrayParenthesis(Loc loc, OutBuffer* buf, size_t start, bool respectBackslashEscapes, ErrorSink eSink)
 {
     uint par_open = 0;
     char inCode = 0;
@@ -589,7 +589,7 @@ private void escapeStrayParenthesis(Loc loc, OutBuffer* buf, size_t start, bool
                 if (par_open == 0)
                 {
                     //stray ')'
-                    warning(loc, "Ddoc: Stray ')'. This may cause incorrect Ddoc output. Use $(RPAREN) instead for unpaired right parentheses.");
+                    eSink.warning(loc, "Ddoc: Stray ')'. This may cause incorrect Ddoc output. Use $(RPAREN) instead for unpaired right parentheses.");
                     buf.remove(u, 1); //remove the )
                     buf.insert(u, "$(RPAREN)"); //insert this instead
                     u += 8; //skip over newly inserted macro
@@ -667,7 +667,7 @@ private void escapeStrayParenthesis(Loc loc, OutBuffer* buf, size_t start, bool
                 if (par_open == 0)
                 {
                     //stray '('
-                    warning(loc, "Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses.");
+                    eSink.warning(loc, "Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses.");
                     buf.remove(u, 1); //remove the (
                     buf.insert(u, "$(LPAREN)"); //insert this instead
                 }
@@ -683,7 +683,7 @@ private void escapeStrayParenthesis(Loc loc, OutBuffer* buf, size_t start, bool
 
 // Basically, this is to skip over things like private{} blocks in a struct or
 // class definition that don't add any components to the qualified name.
-private Scope* skipNonQualScopes(Scope* sc)
+private Scope* skipNonQualScopes(Scope* sc) @safe
 {
     while (sc && !sc.scopesym)
         sc = sc.enclosing;
@@ -1398,7 +1398,7 @@ private void toDocBuffer(Dsymbol s, ref OutBuffer buf, Scope* sc)
             }
         }
 
-        static bool inSameModule(Dsymbol s, Dsymbol p)
+        static bool inSameModule(Dsymbol s, Dsymbol p) @safe
         {
             for (; s; s = s.parent)
             {
@@ -1896,7 +1896,7 @@ struct DocComment
                 buf.writestring("$(DDOC_SUMMARY ");
                 size_t o = buf.length;
                 buf.write(sec.body_);
-                escapeStrayParenthesis(loc, buf, o, true);
+                escapeStrayParenthesis(loc, buf, o, true, sc.eSink);
                 highlightText(sc, a, loc, *buf, o);
                 buf.writestring(")");
             }
@@ -1968,7 +1968,7 @@ private const(char)* skipwhitespace(const(char)* p)
 }
 
 /// Ditto
-private const(char)[] skipwhitespace(const(char)[] p)
+private const(char)[] skipwhitespace(const(char)[] p) @safe
 {
     foreach (idx, char c; p)
     {
@@ -1993,7 +1993,7 @@ private const(char)[] skipwhitespace(const(char)[] p)
  *  chars         = the characters to skip; order is unimportant
  * Returns: the index after skipping characters.
  */
-private size_t skipChars(ref OutBuffer buf, size_t i, string chars)
+private size_t skipChars(ref OutBuffer buf, size_t i, string chars) @safe
 {
     Outer:
     foreach (j, c; buf[][i..$])
@@ -2028,7 +2028,7 @@ unittest {
  *  r = the string to replace `c` with
  * Returns: `s` with `c` replaced with `r`
  */
-private inout(char)[] replaceChar(inout(char)[] s, char c, string r) pure
+private inout(char)[] replaceChar(inout(char)[] s, char c, string r) pure @safe
 {
     int count = 0;
     foreach (char sc; s)
@@ -2070,7 +2070,7 @@ unittest
  *  s = the string to lowercase
  * Returns: the lowercase version of the string or the original if already lowercase
  */
-private string toLowercase(string s) pure
+private string toLowercase(string s) pure @safe
 {
     string lower;
     foreach (size_t i; 0..s.length)
@@ -2112,7 +2112,7 @@ unittest
  *  to    = the index within `buf` to stop counting at, exclusive
  * Returns: the indent
  */
-private int getMarkdownIndent(ref OutBuffer buf, size_t from, size_t to)
+private int getMarkdownIndent(ref OutBuffer buf, size_t from, size_t to) @safe
 {
     const slice = buf[];
     if (to > slice.length)
@@ -2129,7 +2129,7 @@ private int getMarkdownIndent(ref OutBuffer buf, size_t from, size_t to)
  *      beginning of next line
  *      end of buf
  */
-size_t skiptoident(ref OutBuffer buf, size_t i)
+size_t skiptoident(ref OutBuffer buf, size_t i) @safe
 {
     const slice = buf[];
     while (i < slice.length)
@@ -2158,7 +2158,7 @@ size_t skiptoident(ref OutBuffer buf, size_t i)
 /************************************************
  * Scan forward past end of identifier.
  */
-private size_t skippastident(ref OutBuffer buf, size_t i)
+private size_t skippastident(ref OutBuffer buf, size_t i) @safe
 {
     const slice = buf[];
     while (i < slice.length)
@@ -2188,7 +2188,7 @@ private size_t skippastident(ref OutBuffer buf, size_t i)
  * Scan forward past end of an identifier that might
  * contain dots (e.g. `abc.def`)
  */
-private size_t skipPastIdentWithDots(ref OutBuffer buf, size_t i)
+private size_t skipPastIdentWithDots(ref OutBuffer buf, size_t i) @safe
 {
     const slice = buf[];
     bool lastCharWasDot;
@@ -2356,7 +2356,7 @@ private bool replaceMarkdownThematicBreak(ref OutBuffer buf, ref size_t i, size_
  *          the detected heading level from 1 to 6, or
  *          0 if not at an ATX heading
  */
-private int detectAtxHeadingLevel(ref OutBuffer buf, const size_t i)
+private int detectAtxHeadingLevel(ref OutBuffer buf, const size_t i) @safe
 {
     const iHeadingStart = i;
     const iAfterHashes = skipChars(buf, i, "#");
@@ -2566,7 +2566,7 @@ private size_t replaceMarkdownEmphasis(ref OutBuffer buf, const ref Loc loc, ref
 
 /****************************************************
  */
-private bool isIdentifier(Dsymbols* a, const(char)[] s)
+private bool isIdentifier(Dsymbols* a, const(char)[] s) @safe
 {
     foreach (member; *a)
     {
@@ -2744,7 +2744,7 @@ private TemplateParameter isTemplateParameter(Dsymbols* a, const(char)* p, size_
  * Return true if str is a reserved symbol name
  * that starts with a double underscore.
  */
-private bool isReservedName(const(char)[] str)
+private bool isReservedName(const(char)[] str) @safe
 {
     immutable string[] table =
     [
@@ -2802,10 +2802,10 @@ private struct MarkdownDelimiter
     char type;      /// the type of delimiter, defined by its starting character
 
     /// whether this describes a valid delimiter
-    @property bool isValid() const { return count != 0; }
+    @property bool isValid() const @safe { return count != 0; }
 
     /// flag this delimiter as invalid
-    void invalidate() { count = 0; }
+    void invalidate() @safe { count = 0; }
 }
 
 /****************************************************
@@ -2822,7 +2822,7 @@ private struct MarkdownList
     char type;              /// the type of list, defined by its starting character
 
     /// whether this describes a valid list
-    @property bool isValid() const { return type != type.init; }
+    @property bool isValid() const @safe { return type != type.init; }
 
     /****************************************************
      * Try to parse a list item, returning whether successful.
@@ -2832,7 +2832,7 @@ private struct MarkdownList
      *  i             = the index within `buf` of the potential list item
      * Returns: the parsed list item. Its `isValid` property describes whether parsing succeeded.
      */
-    static MarkdownList parseItem(ref OutBuffer buf, size_t iLineStart, size_t i)
+    static MarkdownList parseItem(ref OutBuffer buf, size_t iLineStart, size_t i) @safe
     {
         if (buf[i] == '+' || buf[i] == '-' || buf[i] == '*')
             return parseUnorderedListItem(buf, iLineStart, i);
@@ -2848,7 +2848,7 @@ private struct MarkdownList
      *  i             = the index within `buf` of the list item
      * Returns: whether `i` is at a list item of the same type as this list
      */
-    private bool isAtItemInThisList(ref OutBuffer buf, size_t iLineStart, size_t i)
+    private bool isAtItemInThisList(ref OutBuffer buf, size_t iLineStart, size_t i) @safe
     {
         MarkdownList item = (type == '.' || type == ')') ?
             parseOrderedListItem(buf, iLineStart, i) :
@@ -2970,7 +2970,7 @@ private struct MarkdownList
      *  i             = the index within `buf` of the list item
      * Returns: the parsed list item, or a list item with type `.init` if no list item is available
      */
-    private static MarkdownList parseUnorderedListItem(ref OutBuffer buf, size_t iLineStart, size_t i)
+    private static MarkdownList parseUnorderedListItem(ref OutBuffer buf, size_t iLineStart, size_t i) @safe
     {
         if (i+1 < buf.length &&
                 (buf[i] == '-' ||
@@ -2998,7 +2998,7 @@ private struct MarkdownList
      *  i             = the index within `buf` of the list item
      * Returns: the parsed list item, or a list item with type `.init` if no list item is available
      */
-    private static MarkdownList parseOrderedListItem(ref OutBuffer buf, size_t iLineStart, size_t i)
+    private static MarkdownList parseOrderedListItem(ref OutBuffer buf, size_t iLineStart, size_t i) @safe
     {
         size_t iAfterNumbers = skipChars(buf, i, "0123456789");
         if (iAfterNumbers - i > 0 &&
@@ -3156,7 +3156,7 @@ private struct MarkdownLink
      *  delimiter = the delimiter that starts this link
      * Returns: the index at the end of parsing the link, or `i` if parsing failed.
      */
-    private size_t parseReferenceLink(ref OutBuffer buf, size_t i, MarkdownDelimiter delimiter)
+    private size_t parseReferenceLink(ref OutBuffer buf, size_t i, MarkdownDelimiter delimiter) @safe
     {
         size_t iStart = i + 1;
         size_t iEnd = iStart;
@@ -3233,7 +3233,7 @@ private struct MarkdownLink
      *          If this function returns a non-empty label then `i` will point just after the ']' at the end of the label.
      * Returns: the parsed and normalized label, possibly empty
      */
-    private bool parseLabel(ref OutBuffer buf, ref size_t i)
+    private bool parseLabel(ref OutBuffer buf, ref size_t i) @safe
     {
         if (buf[i] != '[')
             return false;
@@ -3506,7 +3506,7 @@ private struct MarkdownLink
      *  s = the string to remove escaping backslashes from
      * Returns: `s` without escaping backslashes in it
      */
-    private static char[] removeEscapeBackslashes(char[] s)
+    private static char[] removeEscapeBackslashes(char[] s) @safe
     {
         if (!s.length)
             return s;
@@ -3550,7 +3550,7 @@ private struct MarkdownLink
      *  s = the string to percent-encode
      * Returns: `s` with special characters percent-encoded
      */
-    private static inout(char)[] percentEncode(inout(char)[] s) pure
+    private static inout(char)[] percentEncode(inout(char)[] s) pure @safe
     {
         static bool shouldEncode(char c)
         {
@@ -3591,7 +3591,7 @@ private struct MarkdownLink
      *          If this function succeeds `i` will point after the newline.
      * Returns: whether a newline was skipped
      */
-    private static bool skipOneNewline(ref OutBuffer buf, ref size_t i) pure
+    private static bool skipOneNewline(ref OutBuffer buf, ref size_t i) pure @safe
     {
         if (i < buf.length && buf[i] == '\r')
             ++i;
@@ -3786,7 +3786,7 @@ private struct MarkdownLinkReferences
      *  delimiter = the character to split by
      * Returns: the resulting array of strings
      */
-    private static string[] split(string s, char delimiter) pure
+    private static string[] split(string s, char delimiter) pure @safe
     {
         string[] result;
         size_t iStart = 0;
@@ -3893,7 +3893,7 @@ private enum TableColumnAlignment
  *  columnAlignments = alignments to populate for each column
  * Returns: the index of the end of the parsed delimiter, or `0` if not found
  */
-private size_t parseTableDelimiterRow(ref OutBuffer buf, const size_t iStart, bool inQuote, ref TableColumnAlignment[] columnAlignments)
+private size_t parseTableDelimiterRow(ref OutBuffer buf, const size_t iStart, bool inQuote, ref TableColumnAlignment[] columnAlignments) @safe
 {
     size_t i = skipChars(buf, iStart, inQuote ? ">| \t" : "| \t");
     while (i < buf.length && buf[i] != '\r' && buf[i] != '\n')
@@ -4417,7 +4417,7 @@ private void highlightText(Scope* sc, Dsymbols* a, Loc loc, ref OutBuffer buf, s
                     codebuf.write(buf[iCodeStart + count .. i]);
                     // escape the contents, but do not perform highlighting except for DDOC_PSYMBOL
                     highlightCode(sc, a, codebuf, 0);
-                    escapeStrayParenthesis(loc, &codebuf, 0, false);
+                    escapeStrayParenthesis(loc, &codebuf, 0, false, sc.eSink);
                     buf.remove(iCodeStart, i - iCodeStart + count); // also trimming off the current `
                     immutable pre = "$(DDOC_BACKQUOTED ";
                     i = buf.insert(iCodeStart, pre);
@@ -4626,7 +4626,7 @@ private void highlightText(Scope* sc, Dsymbols* a, Loc loc, ref OutBuffer buf, s
                         highlightCode2(sc, a, codebuf, 0);
                     else
                         codebuf.remove(codebuf.length-1, 1);    // remove the trailing 0 byte
-                    escapeStrayParenthesis(loc, &codebuf, 0, false);
+                    escapeStrayParenthesis(loc, &codebuf, 0, false, sc.eSink);
                     buf.remove(iCodeStart, i - iCodeStart);
                     i = buf.insert(iCodeStart, codebuf[]);
                     i = buf.insert(i, ")\n");
@@ -4984,7 +4984,7 @@ private void highlightText(Scope* sc, Dsymbols* a, Loc loc, ref OutBuffer buf, s
     }
 
     if (inCode == '-')
-        error(loc, "unmatched `---` in DDoc comment");
+        sc.eSink.error(loc, "unmatched `---` in DDoc comment");
     else if (inCode)
         buf.insert(buf.length, ")");
 
@@ -5180,10 +5180,10 @@ private void highlightCode3(Scope* sc, ref OutBuffer buf, const(char)* p, const(
  */
 private void highlightCode2(Scope* sc, Dsymbols* a, ref OutBuffer buf, size_t offset)
 {
-    uint errorsave = global.startGagging();
+    scope eSinkNull = new ErrorSinkNull();
 
     scope Lexer lex = new Lexer(null, cast(char*)buf[].ptr, 0, buf.length - 1, 0, 1,
-        global.errorSink,
+        eSinkNull,  // ignore errors
         &global.compileEnv);
     OutBuffer res;
     const(char)* lastp = cast(char*)buf[].ptr;
@@ -5247,7 +5247,6 @@ private void highlightCode2(Scope* sc, Dsymbols* a, ref OutBuffer buf, size_t of
     }
     buf.setsize(offset);
     buf.write(&res);
-    global.endGagging(errorsave);
 }
 
 /****************************************
diff --git a/gcc/d/dmd/doc.h b/gcc/d/dmd/doc.h
index d16806beda2..669e308dcf6 100644
--- a/gcc/d/dmd/doc.h
+++ b/gcc/d/dmd/doc.h
@@ -11,5 +11,6 @@
 #pragma once
 
 class Module;
+class ErrorSink;
 
-void gendocfile(Module *m);
+void gendocfile(Module *m, ErrorSink *eSink);
diff --git a/gcc/d/dmd/dscope.d b/gcc/d/dmd/dscope.d
index 95cfec9c2b9..c2c0628f5ed 100644
--- a/gcc/d/dmd/dscope.d
+++ b/gcc/d/dmd/dscope.d
@@ -29,6 +29,7 @@ import dmd.dsymbolsem;
 import dmd.dtemplate;
 import dmd.expression;
 import dmd.errors;
+import dmd.errorsink;
 import dmd.func;
 import dmd.globals;
 import dmd.id;
@@ -96,6 +97,7 @@ extern (C++) struct Scope
     bool inLoop;                    /// true if inside a loop (where constructor calls aren't allowed)
     int intypeof;                   /// in typeof(exp)
     VarDeclaration lastVar;         /// Previous symbol used to prevent goto-skips-init
+    ErrorSink eSink;                /// sink for error messages
 
     /* If  minst && !tinst, it's in definitely non-speculative scope (eg. module member scope).
      * If !minst && !tinst, it's in definitely speculative scope (eg. template constraint).
@@ -158,7 +160,7 @@ extern (C++) struct Scope
         return new Scope();
     }
 
-    extern (D) static Scope* createGlobal(Module _module)
+    extern (D) static Scope* createGlobal(Module _module, ErrorSink eSink)
     {
         Scope* sc = Scope.alloc();
         *sc = Scope.init;
@@ -166,6 +168,7 @@ extern (C++) struct Scope
         sc.minst = _module;
         sc.scopesym = new ScopeDsymbol();
         sc.scopesym.symtab = new DsymbolTable();
+        sc.eSink = eSink;
         // Add top level package as member of this global scope
         Dsymbol m = _module;
         while (m.parent)
@@ -614,7 +617,7 @@ extern (C++) struct Scope
      * Returns:
      *  innermost scope, null if none
      */
-    extern (D) Scope* inner() return
+    extern (D) Scope* inner() return @safe
     {
         for (Scope* sc = &this; sc; sc = sc.enclosing)
         {
@@ -670,7 +673,7 @@ extern (C++) struct Scope
     /********************************************
      * Search enclosing scopes for ScopeDsymbol.
      */
-    extern (D) ScopeDsymbol getScopesym()
+    extern (D) ScopeDsymbol getScopesym() @safe
     {
         for (Scope* sc = &this; sc; sc = sc.enclosing)
         {
@@ -683,7 +686,7 @@ extern (C++) struct Scope
     /********************************************
      * Search enclosing scopes for ClassDeclaration.
      */
-    extern (D) ClassDeclaration getClassScope()
+    extern (D) ClassDeclaration getClassScope() @safe
     {
         for (Scope* sc = &this; sc; sc = sc.enclosing)
         {
@@ -698,7 +701,7 @@ extern (C++) struct Scope
     /********************************************
      * Search enclosing scopes for ClassDeclaration or StructDeclaration.
      */
-    extern (D) AggregateDeclaration getStructClassScope()
+    extern (D) AggregateDeclaration getStructClassScope() @safe
     {
         for (Scope* sc = &this; sc; sc = sc.enclosing)
         {
@@ -742,7 +745,7 @@ extern (C++) struct Scope
      * where it was declared. So mark the Scope as not
      * to be free'd.
      */
-    extern (D) void setNoFree()
+    extern (D) void setNoFree() @safe
     {
         //int i = 0;
         //printf("Scope::setNoFree(this = %p)\n", this);
diff --git a/gcc/d/dmd/dsymbol.d b/gcc/d/dmd/dsymbol.d
index 23733135fd8..0fa4dbcfa5c 100644
--- a/gcc/d/dmd/dsymbol.d
+++ b/gcc/d/dmd/dsymbol.d
@@ -113,7 +113,7 @@ struct Ungag
 {
     uint oldgag;
 
-    extern (D) this(uint old) nothrow
+    extern (D) this(uint old) nothrow @safe
     {
         this.oldgag = old;
     }
@@ -177,7 +177,7 @@ struct Visibility
     /**
      * Checks if `this` is absolutely identical visibility attribute to `other`
      */
-    bool opEquals(ref const Visibility other) const
+    bool opEquals(ref const Visibility other) const @safe
     {
         if (this.kind == other.kind)
         {
@@ -264,27 +264,27 @@ extern (C++) class Dsymbol : ASTNode
     PASS semanticRun = PASS.initial;
     ushort localNum;        /// perturb mangled name to avoid collisions with those in FuncDeclaration.localsymtab
 
-    final extern (D) this() nothrow
+    final extern (D) this() nothrow @safe
     {
         //printf("Dsymbol::Dsymbol(%p)\n", this);
         loc = Loc(null, 0, 0);
     }
 
-    final extern (D) this(Identifier ident) nothrow
+    final extern (D) this(Identifier ident) nothrow @safe
     {
         //printf("Dsymbol::Dsymbol(%p, ident)\n", this);
         this.loc = Loc(null, 0, 0);
         this.ident = ident;
     }
 
-    final extern (D) this(const ref Loc loc, Identifier ident) nothrow
+    final extern (D) this(const ref Loc loc, Identifier ident) nothrow @safe
     {
         //printf("Dsymbol::Dsymbol(%p, ident)\n", this);
         this.loc = loc;
         this.ident = ident;
     }
 
-    static Dsymbol create(Identifier ident) nothrow
+    static Dsymbol create(Identifier ident) nothrow @safe
     {
         return new Dsymbol(ident);
     }
@@ -353,9 +353,9 @@ extern (C++) class Dsymbol : ASTNode
     {
         if (this == o)
             return true;
-        if (o.dyncast() != DYNCAST.dsymbol)
+        const s = o.isDsymbol();
+        if (!s)
             return false;
-        auto s = cast(Dsymbol)o;
         // Overload sets don't have an ident
         // Function-local declarations may have identical names
         // if they are declared in different scopes
@@ -381,7 +381,7 @@ extern (C++) class Dsymbol : ASTNode
         {
             va_list ap;
             va_start(ap, format);
-            .verror(loc, format, ap, kind(), prettyFormatHelper().ptr);
+            .verrorReport(loc, format, ap, ErrorKind.error, kind(), prettyFormatHelper().ptr);
             va_end(ap);
         }
 
@@ -390,7 +390,7 @@ extern (C++) class Dsymbol : ASTNode
             va_list ap;
             va_start(ap, format);
             const loc = getLoc();
-            .verror(loc, format, ap, kind(), prettyFormatHelper().ptr);
+            .verrorReport(loc, format, ap, ErrorKind.error, kind(), prettyFormatHelper().ptr);
             va_end(ap);
         }
 
@@ -398,7 +398,7 @@ extern (C++) class Dsymbol : ASTNode
         {
             va_list ap;
             va_start(ap, format);
-            .vdeprecation(loc, format, ap, kind(), prettyFormatHelper().ptr);
+            .verrorReport(loc, format, ap, ErrorKind.deprecation, kind(), prettyFormatHelper().ptr);
             va_end(ap);
         }
 
@@ -407,7 +407,7 @@ extern (C++) class Dsymbol : ASTNode
             va_list ap;
             va_start(ap, format);
             const loc = getLoc();
-            .vdeprecation(loc, format, ap, kind(), prettyFormatHelper().ptr);
+            .verrorReport(loc, format, ap, ErrorKind.deprecation, kind(), prettyFormatHelper().ptr);
             va_end(ap);
         }
     }
@@ -417,7 +417,7 @@ extern (C++) class Dsymbol : ASTNode
         {
             va_list ap;
             va_start(ap, format);
-            .verror(loc, format, ap, kind(), prettyFormatHelper().ptr);
+            .verrorReport(loc, format, ap, ErrorKind.error, kind(), prettyFormatHelper().ptr);
             va_end(ap);
         }
 
@@ -426,7 +426,7 @@ extern (C++) class Dsymbol : ASTNode
             va_list ap;
             va_start(ap, format);
             const loc = getLoc();
-            .verror(loc, format, ap, kind(), prettyFormatHelper().ptr);
+            .verrorReport(loc, format, ap, ErrorKind.error, kind(), prettyFormatHelper().ptr);
             va_end(ap);
         }
 
@@ -434,7 +434,7 @@ extern (C++) class Dsymbol : ASTNode
         {
             va_list ap;
             va_start(ap, format);
-            .vdeprecation(loc, format, ap, kind(), prettyFormatHelper().ptr);
+            .verrorReport(loc, format, ap, ErrorKind.deprecation, kind(), prettyFormatHelper().ptr);
             va_end(ap);
         }
 
@@ -443,7 +443,7 @@ extern (C++) class Dsymbol : ASTNode
             va_list ap;
             va_start(ap, format);
             const loc = getLoc();
-            .vdeprecation(loc, format, ap, kind(), prettyFormatHelper().ptr);
+            .verrorReport(loc, format, ap, ErrorKind.deprecation, kind(), prettyFormatHelper().ptr);
             va_end(ap);
         }
     }
@@ -1430,16 +1430,16 @@ private:
     BitArray accessiblePackages, privateAccessiblePackages;// whitelists of accessible (imported) packages
 
 public:
-    final extern (D) this() nothrow
+    final extern (D) this() nothrow @safe
     {
     }
 
-    final extern (D) this(Identifier ident) nothrow
+    final extern (D) this(Identifier ident) nothrow @safe
     {
         super(ident);
     }
 
-    final extern (D) this(const ref Loc loc, Identifier ident) nothrow
+    final extern (D) this(const ref Loc loc, Identifier ident) nothrow @safe
     {
         super(loc, ident);
     }
@@ -1919,7 +1919,7 @@ extern (C++) final class WithScopeSymbol : ScopeDsymbol
 {
     WithStatement withstate;
 
-    extern (D) this(WithStatement withstate) nothrow
+    extern (D) this(WithStatement withstate) nothrow @safe
     {
         this.withstate = withstate;
     }
@@ -1979,7 +1979,7 @@ extern (C++) final class ArrayScopeSymbol : ScopeDsymbol
     private RootObject arrayContent;
     Scope* sc;
 
-    extern (D) this(Scope* sc, Expression exp) nothrow
+    extern (D) this(Scope* sc, Expression exp) nothrow @safe
     {
         super(exp.loc, null);
         assert(exp.op == EXP.index || exp.op == EXP.slice || exp.op == EXP.array);
@@ -1987,13 +1987,13 @@ extern (C++) final class ArrayScopeSymbol : ScopeDsymbol
         this.arrayContent = exp;
     }
 
-    extern (D) this(Scope* sc, TypeTuple type) nothrow
+    extern (D) this(Scope* sc, TypeTuple type) nothrow @safe
     {
         this.sc = sc;
         this.arrayContent = type;
     }
 
-    extern (D) this(Scope* sc, TupleDeclaration td) nothrow
+    extern (D) this(Scope* sc, TupleDeclaration td) nothrow @safe
     {
         this.sc = sc;
         this.arrayContent = td;
@@ -2242,7 +2242,7 @@ extern (C++) final class OverloadSet : Dsymbol
  */
 extern (C++) final class ForwardingScopeDsymbol : ScopeDsymbol
 {
-    extern (D) this() nothrow
+    extern (D) this() nothrow @safe
     {
         super();
     }
@@ -2328,7 +2328,7 @@ extern (C++) final class ForwardingScopeDsymbol : ScopeDsymbol
 extern (C++) final class ExpressionDsymbol : Dsymbol
 {
     Expression exp;
-    this(Expression exp) nothrow
+    this(Expression exp) nothrow @safe
     {
         super();
         this.exp = exp;
@@ -2353,7 +2353,7 @@ extern (C++) final class AliasAssign : Dsymbol
     Dsymbol aliassym; /// replace previous RHS of AliasDeclaration with `aliassym`
                       /// only one of type and aliassym can be != null
 
-    extern (D) this(const ref Loc loc, Identifier ident, Type type, Dsymbol aliassym) nothrow
+    extern (D) this(const ref Loc loc, Identifier ident, Type type, Dsymbol aliassym) nothrow @safe
     {
         super(loc, null);
         this.ident = ident;
diff --git a/gcc/d/dmd/dsymbolsem.d b/gcc/d/dmd/dsymbolsem.d
index 7a800bddd02..378d3e6dd64 100644
--- a/gcc/d/dmd/dsymbolsem.d
+++ b/gcc/d/dmd/dsymbolsem.d
@@ -274,7 +274,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
     alias visit = Visitor.visit;
 
     Scope* sc;
-    this(Scope* sc) scope
+    this(Scope* sc) scope @safe
     {
         this.sc = sc;
     }
@@ -320,11 +320,6 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
             return;
         }
 
-        // @@@DEPRECATED_2.121@@@
-        // Deprecated in 2.101 - Can be removed in 2.121
-        if (ad.isClassDeclaration() || ad.isInterfaceDeclaration())
-            deprecation(dsym.loc, "alias this for classes/interfaces is deprecated");
-
         assert(ad.members);
         Dsymbol s = ad.search(dsym.loc, dsym.ident);
         if (!s)
@@ -1125,16 +1120,12 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
                                  */
                                 if (ne.member && !(ne.member.storage_class & STC.scope_))
                                 {
-                                    if (sc.func.isSafe())
-                                    {
-                                        // @@@DEPRECATED_2.112@@@
-                                        deprecation(dsym.loc,
-                                            "`scope` allocation of `%s` requires that constructor be annotated with `scope`",
-                                            dsym.toChars());
-                                        deprecationSupplemental(ne.member.loc, "is the location of the constructor");
-                                     }
-                                     else
-                                         sc.func.setUnsafe();
+                                    import dmd.escape : setUnsafeDIP1000;
+                                    const inSafeFunc = sc.func && sc.func.isSafeBypassingInference();
+                                    if (sc.setUnsafeDIP1000(false, dsym.loc, "`scope` allocation of `%s` requires that constructor be annotated with `scope`", dsym))
+                                        errorSupplemental(ne.member.loc, "is the location of the constructor");
+                                    else if (global.params.obsolete && inSafeFunc)
+                                        warningSupplemental(ne.member.loc, "is the location of the constructor");
                                 }
                                 ne.onstack = 1;
                                 dsym.onstack = true;
@@ -1224,8 +1215,11 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
                             bool needctfe = dsym.isDataseg() || (dsym.storage_class & STC.manifest);
                             if (needctfe)
                                 sc = sc.startCTFE();
+                            sc = sc.push();
+                            sc.varDecl = dsym; // https://issues.dlang.org/show_bug.cgi?id=24051
                             exp = exp.expressionSemantic(sc);
                             exp = resolveProperties(sc, exp);
+                            sc = sc.pop();
                             if (needctfe)
                                 sc = sc.endCTFE();
                             ei.exp = exp;
@@ -2098,7 +2092,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
         Scope* sc = m._scope; // see if already got one from importAll()
         if (!sc)
         {
-            sc = Scope.createGlobal(m); // create root scope
+            sc = Scope.createGlobal(m, global.errorSink); // create root scope
         }
 
         //printf("Module = %p, linkage = %d\n", sc.scopesym, sc.linkage);
@@ -6087,7 +6081,7 @@ void templateInstanceSemantic(TemplateInstance tempinst, Scope* sc, ArgumentList
                 alias visit = Visitor.visit;
                 TemplateInstance inst;
 
-                extern (D) this(TemplateInstance inst) scope
+                extern (D) this(TemplateInstance inst) scope @safe
                 {
                     this.inst = inst;
                 }
diff --git a/gcc/d/dmd/dtemplate.d b/gcc/d/dmd/dtemplate.d
index f2ab69444bc..e492c7e7aef 100644
--- a/gcc/d/dmd/dtemplate.d
+++ b/gcc/d/dmd/dtemplate.d
@@ -84,7 +84,7 @@ private enum LOG = false;
 
 enum IDX_NOTFOUND = 0x12345678;
 
-pure nothrow @nogc
+pure nothrow @nogc @safe
 {
 
 /********************************************
@@ -3507,7 +3507,7 @@ MATCH deduceType(RootObject o, Scope* sc, Type tparam, TemplateParameters* param
         bool ignoreAliasThis;
         MATCH result;
 
-        extern (D) this(Scope* sc, Type tparam, TemplateParameters* parameters, Objects* dedtypes, uint* wm, size_t inferStart, bool ignoreAliasThis)
+        extern (D) this(Scope* sc, Type tparam, TemplateParameters* parameters, Objects* dedtypes, uint* wm, size_t inferStart, bool ignoreAliasThis) @safe
         {
             this.sc = sc;
             this.tparam = tparam;
@@ -5091,7 +5091,7 @@ private bool reliesOnTemplateParameters(Expression e, TemplateParameter[] tparam
         TemplateParameter[] tparams;
         bool result;
 
-        extern (D) this(TemplateParameter[] tparams)
+        extern (D) this(TemplateParameter[] tparams) @safe
         {
             this.tparams = tparams;
         }
@@ -5358,7 +5358,7 @@ extern (C++) class TemplateParameter : ASTNode
     bool dependent;
 
     /* ======================== TemplateParameter =============================== */
-    extern (D) this(const ref Loc loc, Identifier ident)
+    extern (D) this(const ref Loc loc, Identifier ident) @safe
     {
         this.loc = loc;
         this.ident = ident;
@@ -5433,7 +5433,7 @@ extern (C++) class TemplateTypeParameter : TemplateParameter
 
     extern (D) __gshared Type tdummy = null;
 
-    extern (D) this(const ref Loc loc, Identifier ident, Type specType, Type defaultType)
+    extern (D) this(const ref Loc loc, Identifier ident, Type specType, Type defaultType) @safe
     {
         super(loc, ident);
         this.specType = specType;
@@ -5521,7 +5521,7 @@ extern (C++) class TemplateTypeParameter : TemplateParameter
  */
 extern (C++) final class TemplateThisParameter : TemplateTypeParameter
 {
-    extern (D) this(const ref Loc loc, Identifier ident, Type specType, Type defaultType)
+    extern (D) this(const ref Loc loc, Identifier ident, Type specType, Type defaultType) @safe
     {
         super(loc, ident, specType, defaultType);
     }
@@ -5556,7 +5556,7 @@ extern (C++) final class TemplateValueParameter : TemplateParameter
     extern (D) __gshared Expression[void*] edummies;
 
     extern (D) this(const ref Loc loc, Identifier ident, Type valType,
-        Expression specValue, Expression defaultValue)
+        Expression specValue, Expression defaultValue) @safe
     {
         super(loc, ident);
         this.valType = valType;
@@ -5683,7 +5683,7 @@ extern (C++) final class TemplateAliasParameter : TemplateParameter
 
     extern (D) __gshared Dsymbol sdummy = null;
 
-    extern (D) this(const ref Loc loc, Identifier ident, Type specType, RootObject specAlias, RootObject defaultAlias)
+    extern (D) this(const ref Loc loc, Identifier ident, Type specType, RootObject specAlias, RootObject defaultAlias) @safe
     {
         super(loc, ident);
         this.specType = specType;
@@ -5768,7 +5768,7 @@ extern (C++) final class TemplateAliasParameter : TemplateParameter
  */
 extern (C++) final class TemplateTupleParameter : TemplateParameter
 {
-    extern (D) this(const ref Loc loc, Identifier ident)
+    extern (D) this(const ref Loc loc, Identifier ident) @safe
     {
         super(loc, ident);
     }
@@ -7542,7 +7542,7 @@ extern (C++) class TemplateInstance : ScopeDsymbol
         //printf("TemplateInstance.genIdent('%s')\n", tempdecl.ident.toChars());
         assert(args is tiargs);
         OutBuffer buf;
-        mangleToBuffer(this, &buf);
+        mangleToBuffer(this, buf);
         //printf("\tgenIdent = %s\n", buf.peekChars());
         return Identifier.idPool(buf[]);
     }
@@ -7717,7 +7717,7 @@ void unSpeculative(Scope* sc, RootObject o)
  * Return false if it might be an alias or tuple.
  * (Note that even in this case, it could still turn out to be a value).
  */
-bool definitelyValueParameter(Expression e)
+bool definitelyValueParameter(Expression e) @safe
 {
     // None of these can be value parameters
     if (e.op == EXP.tuple || e.op == EXP.scope_ ||
diff --git a/gcc/d/dmd/dtoh.d b/gcc/d/dmd/dtoh.d
index b9bbad0a7a4..6a7442ad702 100644
--- a/gcc/d/dmd/dtoh.d
+++ b/gcc/d/dmd/dtoh.d
@@ -295,7 +295,7 @@ public:
     // Generates getter-setter methods to replace the use of alias this
     // This should be replaced by a `static foreach` once the gdc tester
     // gets upgraded to version 10 (to support `static foreach`).
-    private extern(D) static string generateMembers()
+    private extern(D) static string generateMembers() @safe
     {
         string result = "";
         foreach(member; __traits(allMembers, Context))
@@ -304,7 +304,6 @@ public:
         }
         return result;
     }
-
     mixin(generateMembers());
 
     this(OutBuffer* fwdbuf, OutBuffer* donebuf, OutBuffer* buf) scope
@@ -396,7 +395,7 @@ public:
     }
 
     /// Writes a final `;` and insert an empty line outside of aggregates
-    private void writeDeclEnd()
+    private void writeDeclEnd() @safe
     {
         buf.writestringln(";");
 
@@ -1213,7 +1212,7 @@ public:
         buf.writestringln("};");
     }
 
-    private bool memberField(AST.VarDeclaration vd)
+    private bool memberField(AST.VarDeclaration vd) @safe
     {
         if (!vd.type || !vd.type.deco || !vd.ident)
             return false;
@@ -1411,7 +1410,7 @@ public:
 
     /// Ends a custom alignment section using `#pragma pack` if
     /// `alignment` specifies a custom alignment
-    private void popAlignToBuffer(structalign_t alignment)
+    private void popAlignToBuffer(structalign_t alignment) @safe
     {
         if (alignment.isDefault() || (tdparent && alignment.isUnknown()))
             return;
@@ -3038,7 +3037,7 @@ public:
     }
 
     /// Returns: Explicit mangling for `sym` if present
-    extern(D) static const(char)[] getMangleOverride(const AST.Dsymbol sym)
+    extern(D) static const(char)[] getMangleOverride(const AST.Dsymbol sym) @safe
     {
         if (auto decl = sym.isDeclaration())
             return decl.mangleOverride;
@@ -3090,34 +3089,34 @@ void initialize()
 }
 
 /// Writes `#if <content>` into the supplied buffer
-void hashIf(ref OutBuffer buf, string content)
+void hashIf(ref OutBuffer buf, string content) @safe
 {
     buf.writestring("#if ");
     buf.writestringln(content);
 }
 
 /// Writes `#elif <content>` into the supplied buffer
-void hashElIf(ref OutBuffer buf, string content)
+void hashElIf(ref OutBuffer buf, string content) @safe
 {
     buf.writestring("#elif ");
     buf.writestringln(content);
 }
 
 /// Writes `#endif` into the supplied buffer
-void hashEndIf(ref OutBuffer buf)
+void hashEndIf(ref OutBuffer buf) @safe
 {
     buf.writestringln("#endif");
 }
 
 /// Writes `#define <content>` into the supplied buffer
-void hashDefine(ref OutBuffer buf, string content)
+void hashDefine(ref OutBuffer buf, string content) @safe
 {
     buf.writestring("#define ");
     buf.writestringln(content);
 }
 
 /// Writes `#include <content>` into the supplied buffer
-void hashInclude(ref OutBuffer buf, string content)
+void hashInclude(ref OutBuffer buf, string content) @safe
 {
     buf.writestring("#include ");
     buf.writestringln(content);
@@ -3232,7 +3231,7 @@ ASTCodegen.Dsymbol outermostSymbol(ASTCodegen.Dsymbol sym)
 
 /// Fetches the symbol for user-defined types from the type `t`
 /// if `t` is either `TypeClass`, `TypeStruct` or `TypeEnum`
-ASTCodegen.Dsymbol symbolFromType(ASTCodegen.Type t)
+ASTCodegen.Dsymbol symbolFromType(ASTCodegen.Type t) @safe
 {
     if (auto tc = t.isTypeClass())
         return tc.sym;
diff --git a/gcc/d/dmd/dversion.d b/gcc/d/dmd/dversion.d
index 259f85c5128..0945b5424b5 100644
--- a/gcc/d/dmd/dversion.d
+++ b/gcc/d/dmd/dversion.d
@@ -35,12 +35,12 @@ extern (C++) final class DebugSymbol : Dsymbol
 {
     uint level;
 
-    extern (D) this(const ref Loc loc, Identifier ident)
+    extern (D) this(const ref Loc loc, Identifier ident) @safe
     {
         super(loc, ident);
     }
 
-    extern (D) this(const ref Loc loc, uint level)
+    extern (D) this(const ref Loc loc, uint level) @safe
     {
         super(loc, null);
         this.level = level;
@@ -129,12 +129,12 @@ extern (C++) final class VersionSymbol : Dsymbol
 {
     uint level;
 
-    extern (D) this(const ref Loc loc, Identifier ident)
+    extern (D) this(const ref Loc loc, Identifier ident) @safe
     {
         super(loc, ident);
     }
 
-    extern (D) this(const ref Loc loc, uint level)
+    extern (D) this(const ref Loc loc, uint level) @safe
     {
         super(loc, null);
         this.level = level;
diff --git a/gcc/d/dmd/errors.d b/gcc/d/dmd/errors.d
index 1f7a78eb6a2..542b97b1ada 100644
--- a/gcc/d/dmd/errors.d
+++ b/gcc/d/dmd/errors.d
@@ -18,6 +18,16 @@ import dmd.location;
 
 nothrow:
 
+/// Constants used to discriminate kinds of error messages.
+enum ErrorKind
+{
+    warning,
+    deprecation,
+    error,
+    tip,
+    message,
+}
+
 /***************************
  * Error message sink for D compiler.
  */
@@ -31,7 +41,7 @@ class ErrorSinkCompiler : ErrorSink
     {
         va_list ap;
         va_start(ap, format);
-        verror(loc, format, ap);
+        verrorReport(loc, format, ap, ErrorKind.error);
         va_end(ap);
     }
 
@@ -39,7 +49,7 @@ class ErrorSinkCompiler : ErrorSink
     {
         va_list ap;
         va_start(ap, format);
-        verrorSupplemental(loc, format, ap);
+        verrorReportSupplemental(loc, format, ap, ErrorKind.error);
         va_end(ap);
     }
 
@@ -47,7 +57,15 @@ class ErrorSinkCompiler : ErrorSink
     {
         va_list ap;
         va_start(ap, format);
-        vwarning(loc, format, ap);
+        verrorReport(loc, format, ap, ErrorKind.warning);
+        va_end(ap);
+    }
+
+    void warningSupplemental(const ref Loc loc, const(char)* format, ...)
+    {
+        va_list ap;
+        va_start(ap, format);
+        verrorReportSupplemental(loc, format, ap, ErrorKind.warning);
         va_end(ap);
     }
 
@@ -55,7 +73,7 @@ class ErrorSinkCompiler : ErrorSink
     {
         va_list ap;
         va_start(ap, format);
-        vdeprecation(loc, format, ap);
+        verrorReport(loc, format, ap, ErrorKind.deprecation);
         va_end(ap);
     }
 
@@ -63,7 +81,7 @@ class ErrorSinkCompiler : ErrorSink
     {
         va_list ap;
         va_start(ap, format);
-        vdeprecationSupplemental(loc, format, ap);
+        verrorReportSupplemental(loc, format, ap, ErrorKind.deprecation);
         va_end(ap);
     }
 
@@ -71,7 +89,7 @@ class ErrorSinkCompiler : ErrorSink
     {
         va_list ap;
         va_start(ap, format);
-        vmessage(loc, format, ap);
+        verrorReport(loc, format, ap, ErrorKind.message);
         va_end(ap);
     }
 }
@@ -160,7 +178,7 @@ static if (__VERSION__ < 2092)
     {
         va_list ap;
         va_start(ap, format);
-        verror(loc, format, ap);
+        verrorReport(loc, format, ap, ErrorKind.error);
         va_end(ap);
     }
 else
@@ -168,7 +186,7 @@ else
     {
         va_list ap;
         va_start(ap, format);
-        verror(loc, format, ap);
+        verrorReport(loc, format, ap, ErrorKind.error);
         va_end(ap);
     }
 
@@ -187,7 +205,7 @@ static if (__VERSION__ < 2092)
         const loc = Loc(filename, linnum, charnum);
         va_list ap;
         va_start(ap, format);
-        verror(loc, format, ap);
+        verrorReport(loc, format, ap, ErrorKind.error);
         va_end(ap);
     }
 else
@@ -196,7 +214,7 @@ else
         const loc = Loc(filename, linnum, charnum);
         va_list ap;
         va_start(ap, format);
-        verror(loc, format, ap);
+        verrorReport(loc, format, ap, ErrorKind.error);
         va_end(ap);
     }
 
@@ -213,7 +231,7 @@ static if (__VERSION__ < 2092)
     {
         va_list ap;
         va_start(ap, format);
-        verrorSupplemental(loc, format, ap);
+        verrorReportSupplemental(loc, format, ap, ErrorKind.error);
         va_end(ap);
     }
 else
@@ -221,7 +239,7 @@ else
     {
         va_list ap;
         va_start(ap, format);
-        verrorSupplemental(loc, format, ap);
+        verrorReportSupplemental(loc, format, ap, ErrorKind.error);
         va_end(ap);
     }
 
@@ -237,7 +255,7 @@ static if (__VERSION__ < 2092)
     {
         va_list ap;
         va_start(ap, format);
-        vwarning(loc, format, ap);
+        verrorReport(loc, format, ap, ErrorKind.warning);
         va_end(ap);
     }
 else
@@ -245,7 +263,7 @@ else
     {
         va_list ap;
         va_start(ap, format);
-        vwarning(loc, format, ap);
+        verrorReport(loc, format, ap, ErrorKind.warning);
         va_end(ap);
     }
 
@@ -262,7 +280,7 @@ static if (__VERSION__ < 2092)
     {
         va_list ap;
         va_start(ap, format);
-        vwarningSupplemental(loc, format, ap);
+        verrorReportSupplemental(loc, format, ap, ErrorKind.warning);
         va_end(ap);
     }
 else
@@ -270,7 +288,7 @@ else
     {
         va_list ap;
         va_start(ap, format);
-        vwarningSupplemental(loc, format, ap);
+        verrorReportSupplemental(loc, format, ap, ErrorKind.warning);
         va_end(ap);
     }
 
@@ -287,7 +305,7 @@ static if (__VERSION__ < 2092)
     {
         va_list ap;
         va_start(ap, format);
-        vdeprecation(loc, format, ap);
+        verrorReport(loc, format, ap, ErrorKind.deprecation);
         va_end(ap);
     }
 else
@@ -295,7 +313,7 @@ else
     {
         va_list ap;
         va_start(ap, format);
-        vdeprecation(loc, format, ap);
+        verrorReport(loc, format, ap, ErrorKind.deprecation);
         va_end(ap);
     }
 
@@ -312,7 +330,7 @@ static if (__VERSION__ < 2092)
     {
         va_list ap;
         va_start(ap, format);
-        vdeprecationSupplemental(loc, format, ap);
+        verrorReportSupplemental(loc, format, ap, ErrorKind.deprecation);
         va_end(ap);
     }
 else
@@ -320,7 +338,7 @@ else
     {
         va_list ap;
         va_start(ap, format);
-        vdeprecationSupplemental(loc, format, ap);
+        verrorReportSupplemental(loc, format, ap, ErrorKind.deprecation);
         va_end(ap);
     }
 
@@ -337,7 +355,7 @@ static if (__VERSION__ < 2092)
     {
         va_list ap;
         va_start(ap, format);
-        vmessage(loc, format, ap);
+        verrorReport(loc, format, ap, ErrorKind.message);
         va_end(ap);
     }
 else
@@ -345,7 +363,7 @@ else
     {
         va_list ap;
         va_start(ap, format);
-        vmessage(loc, format, ap);
+        verrorReport(loc, format, ap, ErrorKind.message);
         va_end(ap);
     }
 
@@ -360,7 +378,7 @@ static if (__VERSION__ < 2092)
     {
         va_list ap;
         va_start(ap, format);
-        vmessage(Loc.initial, format, ap);
+        verrorReport(Loc.initial, format, ap, ErrorKind.message);
         va_end(ap);
     }
 else
@@ -368,13 +386,13 @@ else
     {
         va_list ap;
         va_start(ap, format);
-        vmessage(Loc.initial, format, ap);
+        verrorReport(Loc.initial, format, ap, ErrorKind.message);
         va_end(ap);
     }
 
 /**
  * The type of the diagnostic handler
- * see verrorPrint for arguments
+ * see verrorReport for arguments
  * Returns: true if error handling is done, false to continue printing to stderr
  */
 alias DiagnosticHandler = bool delegate(const ref Loc location, Color headerColor, const(char)* header, const(char)* messageFormat, va_list args, const(char)* prefix1, const(char)* prefix2);
@@ -397,7 +415,7 @@ static if (__VERSION__ < 2092)
     {
         va_list ap;
         va_start(ap, format);
-        vtip(format, ap);
+        verrorReport(Loc.initial, format, ap, ErrorKind.tip);
         va_end(ap);
     }
 else
@@ -405,104 +423,38 @@ else
     {
         va_list ap;
         va_start(ap, format);
-        vtip(format, ap);
+        verrorReport(Loc.initial, format, ap, ErrorKind.tip);
         va_end(ap);
     }
 
 
 /**
- * Same as $(D error), but takes a va_list parameter, and optionally additional message prefixes.
+ * Implements $(D error), $(D warning), $(D deprecation), $(D message), and
+ * $(D tip). Report a diagnostic error, taking a va_list parameter, and
+ * optionally additional message prefixes. Whether the message gets printed
+ * depends on runtime values of DiagnosticReporting and global gagging.
  * Params:
- *      loc    = location of error
- *      format = printf-style format specification
- *      ap     = printf-style variadic arguments
- *      p1     = additional message prefix
- *      p2     = additional message prefix
- *      header = title of error message
+ *      loc         = location of error
+ *      format      = printf-style format specification
+ *      ap          = printf-style variadic arguments
+ *      kind        = kind of error being printed
+ *      p1          = additional message prefix
+ *      p2          = additional message prefix
  */
-extern (C++) void verror(const ref Loc loc, const(char)* format, va_list ap, const(char)* p1 = null, const(char)* p2 = null, const(char)* header = "Error: ");
+extern (C++) void verrorReport(const ref Loc loc, const(char)* format, va_list ap, ErrorKind kind, const(char)* p1 = null, const(char)* p2 = null);
 
 /**
- * Same as $(D errorSupplemental), but takes a va_list parameter.
+ * Implements $(D errorSupplemental), $(D warningSupplemental), and
+ * $(D deprecationSupplemental). Report an addition diagnostic error, taking a
+ * va_list parameter. Whether the message gets printed depends on runtime
+ * values of DiagnosticReporting and global gagging.
  * Params:
- *      loc    = location of error
- *      format = printf-style format specification
- *      ap     = printf-style variadic arguments
- */
-static if (__VERSION__ < 2092)
-    extern (C++) void verrorSupplemental(const ref Loc loc, const(char)* format, va_list ap);
-else
-    pragma(printf) extern (C++) void verrorSupplemental(const ref Loc loc, const(char)* format, va_list ap);
-
-/**
- * Same as $(D warning), but takes a va_list parameter.
- * Params:
- *      loc    = location of warning
- *      format = printf-style format specification
- *      ap     = printf-style variadic arguments
- */
-static if (__VERSION__ < 2092)
-    extern (C++) void vwarning(const ref Loc loc, const(char)* format, va_list ap);
-else
-    pragma(printf) extern (C++) void vwarning(const ref Loc loc, const(char)* format, va_list ap);
-
-/**
- * Same as $(D warningSupplemental), but takes a va_list parameter.
- * Params:
- *      loc    = location of warning
- *      format = printf-style format specification
- *      ap     = printf-style variadic arguments
+ *      loc         = location of error
+ *      format      = printf-style format specification
+ *      ap          = printf-style variadic arguments
+ *      kind        = kind of error being printed
  */
-static if (__VERSION__ < 2092)
-    extern (C++) void vwarningSupplemental(const ref Loc loc, const(char)* format, va_list ap);
-else
-    pragma(printf) extern (C++) void vwarningSupplemental(const ref Loc loc, const(char)* format, va_list ap);
-
-/**
- * Same as $(D deprecation), but takes a va_list parameter, and optionally additional message prefixes.
- * Params:
- *      loc    = location of deprecation
- *      format = printf-style format specification
- *      ap     = printf-style variadic arguments
- *      p1     = additional message prefix
- *      p2     = additional message prefix
- */
-extern (C++) void vdeprecation(const ref Loc loc, const(char)* format, va_list ap, const(char)* p1 = null, const(char)* p2 = null);
-
-/**
- * Same as $(D message), but takes a va_list parameter.
- * Params:
- *      loc       = location of message
- *      format    = printf-style format specification
- *      ap        = printf-style variadic arguments
- */
-static if (__VERSION__ < 2092)
-    extern (C++) void vmessage(const ref Loc loc, const(char)* format, va_list ap);
-else
-    pragma(printf) extern (C++) void vmessage(const ref Loc loc, const(char)* format, va_list ap);
-
-/**
- * Same as $(D tip), but takes a va_list parameter.
- * Params:
- *      format    = printf-style format specification
- *      ap        = printf-style variadic arguments
- */
-static if (__VERSION__ < 2092)
-    extern (C++) void vtip(const(char)* format, va_list ap);
-else
-    pragma(printf) extern (C++) void vtip(const(char)* format, va_list ap);
-
-/**
- * Same as $(D deprecationSupplemental), but takes a va_list parameter.
- * Params:
- *      loc    = location of deprecation
- *      format = printf-style format specification
- *      ap     = printf-style variadic arguments
- */
-static if (__VERSION__ < 2092)
-    extern (C++) void vdeprecationSupplemental(const ref Loc loc, const(char)* format, va_list ap);
-else
-    pragma(printf) extern (C++) void vdeprecationSupplemental(const ref Loc loc, const(char)* format, va_list ap);
+extern (C++) void verrorReportSupplemental(const ref Loc loc, const(char)* format, va_list ap, ErrorKind kind);
 
 /**
  * The type of the fatal error handler
@@ -526,4 +478,4 @@ extern (C++) void fatal();
  * Try to stop forgetting to remove the breakpoints from
  * release builds.
  */
-extern (C++) void halt();
+extern (C++) void halt() @safe;
diff --git a/gcc/d/dmd/errors.h b/gcc/d/dmd/errors.h
index cc72811b112..c6b5975113a 100644
--- a/gcc/d/dmd/errors.h
+++ b/gcc/d/dmd/errors.h
@@ -14,6 +14,15 @@
 
 struct Loc;
 
+enum class ErrorKind
+{
+    warning = 0,
+    deprecation = 1,
+    error = 2,
+    tip = 3,
+    message = 4,
+};
+
 bool isConsoleColorSupported();
 
 #if defined(__GNUC__)
@@ -30,17 +39,12 @@ D_ATTRIBUTE_FORMAT(2, 3) void deprecationSupplemental(const Loc& loc, const char
 D_ATTRIBUTE_FORMAT(2, 3) void error(const Loc& loc, const char *format, ...);
 D_ATTRIBUTE_FORMAT(4, 5) void error(const char *filename, unsigned linnum, unsigned charnum, const char *format, ...);
 D_ATTRIBUTE_FORMAT(2, 3) void errorSupplemental(const Loc& loc, const char *format, ...);
-D_ATTRIBUTE_FORMAT(2, 0) void verror(const Loc& loc, const char *format, va_list ap, const char *p1 = NULL, const char *p2 = NULL, const char *header = "Error: ");
-D_ATTRIBUTE_FORMAT(2, 0) void verrorSupplemental(const Loc& loc, const char *format, va_list ap);
-D_ATTRIBUTE_FORMAT(2, 0) void vwarning(const Loc& loc, const char *format, va_list);
-D_ATTRIBUTE_FORMAT(2, 0) void vwarningSupplemental(const Loc& loc, const char *format, va_list ap);
-D_ATTRIBUTE_FORMAT(2, 0) void vdeprecation(const Loc& loc, const char *format, va_list ap, const char *p1 = NULL, const char *p2 = NULL);
-D_ATTRIBUTE_FORMAT(2, 0) void vdeprecationSupplemental(const Loc& loc, const char *format, va_list ap);
 D_ATTRIBUTE_FORMAT(1, 2) void message(const char *format, ...);
 D_ATTRIBUTE_FORMAT(2, 3) void message(const Loc& loc, const char *format, ...);
-D_ATTRIBUTE_FORMAT(2, 0) void vmessage(const Loc& loc, const char *format, va_list ap);
 D_ATTRIBUTE_FORMAT(1, 2) void tip(const char *format, ...);
-D_ATTRIBUTE_FORMAT(1, 0) void vtip(const char *format, va_list ap);
+
+D_ATTRIBUTE_FORMAT(2, 0) void verrorReport(const Loc& loc, const char *format, va_list ap, const char *p1 = NULL, const char *p2 = NULL);
+D_ATTRIBUTE_FORMAT(2, 0) void verrorReportSupplemental(const Loc& loc, const char* format, va_list ap, ErrorKind kind);
 
 #if defined(__GNUC__) || defined(__clang__)
 #define D_ATTRIBUTE_NORETURN __attribute__((noreturn))
diff --git a/gcc/d/dmd/errorsink.d b/gcc/d/dmd/errorsink.d
index e57c2b6e388..e14829ecfdb 100644
--- a/gcc/d/dmd/errorsink.d
+++ b/gcc/d/dmd/errorsink.d
@@ -27,6 +27,8 @@ abstract class ErrorSink
 
     void warning(const ref Loc loc, const(char)* format, ...);
 
+    void warningSupplemental(const ref Loc loc, const(char)* format, ...);
+
     void message(const ref Loc loc, const(char)* format, ...);
 
     void deprecation(const ref Loc loc, const(char)* format, ...);
@@ -49,6 +51,8 @@ class ErrorSinkNull : ErrorSink
 
     void warning(const ref Loc loc, const(char)* format, ...) { }
 
+    void warningSupplemental(const ref Loc loc, const(char)* format, ...) { }
+
     void message(const ref Loc loc, const(char)* format, ...) { }
 
     void deprecation(const ref Loc loc, const(char)* format, ...) { }
@@ -104,6 +108,8 @@ class ErrorSinkStderr : ErrorSink
         va_end(ap);
     }
 
+    void warningSupplemental(const ref Loc loc, const(char)* format, ...) { }
+
     void deprecation(const ref Loc loc, const(char)* format, ...)
     {
         fputs("Deprecation: ", stderr);
diff --git a/gcc/d/dmd/escape.d b/gcc/d/dmd/escape.d
index efd6bea6821..f817a4ee42f 100644
--- a/gcc/d/dmd/escape.d
+++ b/gcc/d/dmd/escape.d
@@ -2561,7 +2561,7 @@ private void addMaybe(VarDeclaration va, VarDeclaration v)
 }
 
 // `setUnsafePreview` partially evaluated for dip1000
-private bool setUnsafeDIP1000(Scope* sc, bool gag, Loc loc, const(char)* msg,
+bool setUnsafeDIP1000(Scope* sc, bool gag, Loc loc, const(char)* msg,
     RootObject arg0 = null, RootObject arg1 = null, RootObject arg2 = null)
 {
     return setUnsafePreview(sc, global.params.useDIP1000, gag, loc, msg, arg0, arg1, arg2);
diff --git a/gcc/d/dmd/expression.d b/gcc/d/dmd/expression.d
index 9477867e929..07cc8d4b7e8 100644
--- a/gcc/d/dmd/expression.d
+++ b/gcc/d/dmd/expression.d
@@ -421,7 +421,7 @@ int expandAliasThisTuples(Expressions* exps, size_t starti = 0)
  * Returns:
  *      template for that function, otherwise null
  */
-TemplateDeclaration getFuncTemplateDecl(Dsymbol s)
+TemplateDeclaration getFuncTemplateDecl(Dsymbol s) @safe
 {
     FuncDeclaration f = s.isFuncDeclaration();
     if (f && f.parent)
@@ -636,7 +636,7 @@ private:
  *      true if x1 is x2
  *      else false
  */
-bool RealIdentical(real_t x1, real_t x2)
+bool RealIdentical(real_t x1, real_t x2) @safe
 {
     return (CTFloat.isNaN(x1) && CTFloat.isNaN(x2)) || CTFloat.isIdentical(x1, x2);
 }
@@ -648,7 +648,7 @@ bool RealIdentical(real_t x1, real_t x2)
  *      (foo).size
  *      cast(foo).size
  */
-DotIdExp typeDotIdExp(const ref Loc loc, Type type, Identifier ident)
+DotIdExp typeDotIdExp(const ref Loc loc, Type type, Identifier ident) @safe
 {
     return new DotIdExp(loc, new TypeExp(loc, type), ident);
 }
@@ -738,7 +738,7 @@ extern (C++) abstract class Expression : ASTNode
     Loc loc;        // file location
     const EXP op;   // to minimize use of dynamic_cast
 
-    extern (D) this(const ref Loc loc, EXP op) scope
+    extern (D) this(const ref Loc loc, EXP op) scope @safe
     {
         //printf("Expression::Expression(op = %d) this = %p\n", op, this);
         this.loc = loc;
@@ -825,7 +825,7 @@ extern (C++) abstract class Expression : ASTNode
             {
                 va_list ap;
                 va_start(ap, format);
-                .verror(loc, format, ap);
+                .verrorReport(loc, format, ap, ErrorKind.error);
                 va_end(ap);
             }
         }
@@ -837,7 +837,7 @@ extern (C++) abstract class Expression : ASTNode
 
             va_list ap;
             va_start(ap, format);
-            .verrorSupplemental(loc, format, ap);
+            .verrorReportSupplemental(loc, format, ap, ErrorKind.error);
             va_end(ap);
         }
 
@@ -847,7 +847,7 @@ extern (C++) abstract class Expression : ASTNode
             {
                 va_list ap;
                 va_start(ap, format);
-                .vwarning(loc, format, ap);
+                .verrorReport(loc, format, ap, ErrorKind.warning);
                 va_end(ap);
             }
         }
@@ -858,7 +858,7 @@ extern (C++) abstract class Expression : ASTNode
             {
                 va_list ap;
                 va_start(ap, format);
-                .vdeprecation(loc, format, ap);
+                .verrorReport(loc, format, ap, ErrorKind.deprecation);
                 va_end(ap);
             }
         }
@@ -871,7 +871,7 @@ extern (C++) abstract class Expression : ASTNode
             {
                 va_list ap;
                 va_start(ap, format);
-                .verror(loc, format, ap);
+                .verrorReport(loc, format, ap, ErrorKind.error);
                 va_end(ap);
             }
         }
@@ -883,7 +883,7 @@ extern (C++) abstract class Expression : ASTNode
 
             va_list ap;
             va_start(ap, format);
-            .verrorSupplemental(loc, format, ap);
+            .verrorReportSupplemental(loc, format, ap, ErrorKind.error);
             va_end(ap);
         }
 
@@ -893,7 +893,7 @@ extern (C++) abstract class Expression : ASTNode
             {
                 va_list ap;
                 va_start(ap, format);
-                .vwarning(loc, format, ap);
+                .verrorReport(loc, format, ap, ErrorKind.warning);
                 va_end(ap);
             }
         }
@@ -904,7 +904,7 @@ extern (C++) abstract class Expression : ASTNode
             {
                 va_list ap;
                 va_start(ap, format);
-                .vdeprecation(loc, format, ap);
+                .verrorReport(loc, format, ap, ErrorKind.deprecation);
                 va_end(ap);
             }
         }
@@ -913,7 +913,7 @@ extern (C++) abstract class Expression : ASTNode
     /**********************************
      * Combine e1 and e2 by CommaExp if both are not NULL.
      */
-    extern (D) static Expression combine(Expression e1, Expression e2)
+    extern (D) static Expression combine(Expression e1, Expression e2) @safe
     {
         if (e1)
         {
@@ -928,12 +928,12 @@ extern (C++) abstract class Expression : ASTNode
         return e1;
     }
 
-    extern (D) static Expression combine(Expression e1, Expression e2, Expression e3)
+    extern (D) static Expression combine(Expression e1, Expression e2, Expression e3) @safe
     {
         return combine(combine(e1, e2), e3);
     }
 
-    extern (D) static Expression combine(Expression e1, Expression e2, Expression e3, Expression e4)
+    extern (D) static Expression combine(Expression e1, Expression e2, Expression e3, Expression e4) @safe
     {
         return combine(combine(e1, e2), combine(e3, e4));
     }
@@ -944,7 +944,7 @@ extern (C++) abstract class Expression : ASTNode
      * is returned via e0.
      * Otherwise 'e' is directly returned and e0 is set to NULL.
      */
-    extern (D) static Expression extractLast(Expression e, out Expression e0)
+    extern (D) static Expression extractLast(Expression e, out Expression e0) @safe
     {
         if (e.op != EXP.comma)
         {
@@ -1485,6 +1485,7 @@ extern (C++) abstract class Expression : ASTNode
                 else
                 {
                     sc.varDecl.storage_class |= STC.system;
+                    sc.varDecl.systemInferred = true;
                 }
             }
             return false;
@@ -1620,7 +1621,9 @@ extern (C++) abstract class Expression : ASTNode
             {
                 //printf("checkRightThis sc.intypeof = %d, ad = %p, func = %p, fdthis = %p\n",
                 //        sc.intypeof, sc.getStructClassScope(), func, fdthis);
-                error("need `this` for `%s` of type `%s`", ve.var.toChars(), ve.var.type.toChars());
+                auto t = ve.var.isThis();
+                assert(t);
+                error("accessing non-static variable `%s` requires an instance of `%s`", ve.var.toChars(), t.toChars());
                 return true;
             }
         }
@@ -2157,7 +2160,7 @@ extern (C++) final class VoidInitExp : Expression
     VarDeclaration var; /// the variable from where the void value came from, null if not known
                         /// Useful for error messages
 
-    extern (D) this(VarDeclaration var)
+    extern (D) this(VarDeclaration var) @safe
     {
         super(var.loc, EXP.void_);
         this.var = var;
@@ -2183,7 +2186,7 @@ extern (C++) final class RealExp : Expression
 {
     real_t value;
 
-    extern (D) this(const ref Loc loc, real_t value, Type type)
+    extern (D) this(const ref Loc loc, real_t value, Type type) @safe
     {
         super(loc, EXP.float64);
         //printf("RealExp::RealExp(%Lg)\n", value);
@@ -2191,7 +2194,7 @@ extern (C++) final class RealExp : Expression
         this.type = type;
     }
 
-    static RealExp create(const ref Loc loc, real_t value, Type type)
+    static RealExp create(const ref Loc loc, real_t value, Type type) @safe
     {
         return new RealExp(loc, value, type);
     }
@@ -2266,7 +2269,7 @@ extern (C++) final class ComplexExp : Expression
 {
     complex_t value;
 
-    extern (D) this(const ref Loc loc, complex_t value, Type type)
+    extern (D) this(const ref Loc loc, complex_t value, Type type) @safe
     {
         super(loc, EXP.complex80);
         this.value = value;
@@ -2274,7 +2277,7 @@ extern (C++) final class ComplexExp : Expression
         //printf("ComplexExp::ComplexExp(%s)\n", toChars());
     }
 
-    static ComplexExp create(const ref Loc loc, complex_t value, Type type)
+    static ComplexExp create(const ref Loc loc, complex_t value, Type type) @safe
     {
         return new ComplexExp(loc, value, type);
     }
@@ -2358,13 +2361,13 @@ extern (C++) class IdentifierExp : Expression
     Identifier ident;
     bool parens;        // if it appears as (identifier)
 
-    extern (D) this(const ref Loc loc, Identifier ident) scope
+    extern (D) this(const ref Loc loc, Identifier ident) scope @safe
     {
         super(loc, EXP.identifier);
         this.ident = ident;
     }
 
-    static IdentifierExp create(const ref Loc loc, Identifier ident)
+    static IdentifierExp create(const ref Loc loc, Identifier ident) @safe
     {
         return new IdentifierExp(loc, ident);
     }
@@ -2411,7 +2414,7 @@ extern (C++) final class DsymbolExp : Expression
     Dsymbol s;
     bool hasOverloads;
 
-    extern (D) this(const ref Loc loc, Dsymbol s, bool hasOverloads = true)
+    extern (D) this(const ref Loc loc, Dsymbol s, bool hasOverloads = true) @safe
     {
         super(loc, EXP.dSymbol);
         this.s = s;
@@ -2441,13 +2444,13 @@ extern (C++) class ThisExp : Expression
 {
     VarDeclaration var;
 
-    extern (D) this(const ref Loc loc)
+    extern (D) this(const ref Loc loc) @safe
     {
         super(loc, EXP.this_);
         //printf("ThisExp::ThisExp() loc = %d\n", loc.linnum);
     }
 
-    this(const ref Loc loc, const EXP tok)
+    this(const ref Loc loc, const EXP tok) @safe
     {
         super(loc, tok);
         //printf("ThisExp::ThisExp() loc = %d\n", loc.linnum);
@@ -2489,7 +2492,7 @@ extern (C++) class ThisExp : Expression
  */
 extern (C++) final class SuperExp : ThisExp
 {
-    extern (D) this(const ref Loc loc)
+    extern (D) this(const ref Loc loc) @safe
     {
         super(loc, EXP.super_);
     }
@@ -2519,7 +2522,7 @@ extern (C++) final class SuperExp : ThisExp
  */
 extern (C++) final class NullExp : Expression
 {
-    extern (D) this(const ref Loc loc, Type type = null) scope
+    extern (D) this(const ref Loc loc, Type type = null) scope @safe
     {
         super(loc, EXP.null_);
         this.type = type;
@@ -2983,7 +2986,7 @@ extern (C++) final class TupleExp : Expression
 
     Expressions* exps;
 
-    extern (D) this(const ref Loc loc, Expression e0, Expressions* exps)
+    extern (D) this(const ref Loc loc, Expression e0, Expressions* exps) @safe
     {
         super(loc, EXP.tuple);
         //printf("TupleExp(this = %p)\n", this);
@@ -2991,7 +2994,7 @@ extern (C++) final class TupleExp : Expression
         this.exps = exps;
     }
 
-    extern (D) this(const ref Loc loc, Expressions* exps)
+    extern (D) this(const ref Loc loc, Expressions* exps) @safe
     {
         super(loc, EXP.tuple);
         //printf("TupleExp(this = %p)\n", this);
@@ -3032,7 +3035,7 @@ extern (C++) final class TupleExp : Expression
         }
     }
 
-    static TupleExp create(const ref Loc loc, Expressions* exps)
+    static TupleExp create(const ref Loc loc, Expressions* exps) @safe
     {
         return new TupleExp(loc, exps);
     }
@@ -3088,7 +3091,7 @@ extern (C++) final class ArrayLiteralExp : Expression
 
     Expressions* elements;
 
-    extern (D) this(const ref Loc loc, Type type, Expressions* elements)
+    extern (D) this(const ref Loc loc, Type type, Expressions* elements) @safe
     {
         super(loc, EXP.arrayLiteral);
         this.type = type;
@@ -3103,7 +3106,7 @@ extern (C++) final class ArrayLiteralExp : Expression
         elements.push(e);
     }
 
-    extern (D) this(const ref Loc loc, Type type, Expression basis, Expressions* elements)
+    extern (D) this(const ref Loc loc, Type type, Expression basis, Expressions* elements) @safe
     {
         super(loc, EXP.arrayLiteral);
         this.type = type;
@@ -3111,7 +3114,7 @@ extern (C++) final class ArrayLiteralExp : Expression
         this.elements = elements;
     }
 
-    static ArrayLiteralExp create(const ref Loc loc, Expressions* elements)
+    static ArrayLiteralExp create(const ref Loc loc, Expressions* elements) @safe
     {
         return new ArrayLiteralExp(loc, null, elements);
     }
@@ -3248,7 +3251,7 @@ extern (C++) final class AssocArrayLiteralExp : Expression
     Expressions* keys;
     Expressions* values;
 
-    extern (D) this(const ref Loc loc, Expressions* keys, Expressions* values)
+    extern (D) this(const ref Loc loc, Expressions* keys, Expressions* values) @safe
     {
         super(loc, EXP.assocArrayLiteral);
         assert(keys.length == values.length);
@@ -3347,7 +3350,7 @@ extern (C++) final class StructLiteralExp : Expression
     bool isOriginal = false; /// used when moving instances to indicate `this is this.origin`
     OwnedBy ownedByCtfe = OwnedBy.code;
 
-    extern (D) this(const ref Loc loc, StructDeclaration sd, Expressions* elements, Type stype = null)
+    extern (D) this(const ref Loc loc, StructDeclaration sd, Expressions* elements, Type stype = null) @safe
     {
         super(loc, EXP.structLiteral);
         this.sd = sd;
@@ -3526,7 +3529,7 @@ extern (C++) final class CompoundLiteralExp : Expression
 {
     Initializer initializer; /// initializer-list
 
-    extern (D) this(const ref Loc loc, Type type_name, Initializer initializer)
+    extern (D) this(const ref Loc loc, Type type_name, Initializer initializer) @safe
     {
         super(loc, EXP.compoundLiteral);
         super.type = type_name;
@@ -3547,7 +3550,7 @@ extern (C++) final class TypeExp : Expression
 {
     bool parens;    // if this is a parenthesized expression
 
-    extern (D) this(const ref Loc loc, Type type)
+    extern (D) this(const ref Loc loc, Type type) @safe
     {
         super(loc, EXP.type);
         //printf("TypeExp::TypeExp(%s)\n", type.toChars());
@@ -3589,7 +3592,7 @@ extern (C++) final class ScopeExp : Expression
 {
     ScopeDsymbol sds;
 
-    extern (D) this(const ref Loc loc, ScopeDsymbol sds)
+    extern (D) this(const ref Loc loc, ScopeDsymbol sds) @safe
     {
         super(loc, EXP.scope_);
         //printf("ScopeExp::ScopeExp(sds = '%s')\n", sds.toChars());
@@ -3644,7 +3647,7 @@ extern (C++) final class TemplateExp : Expression
     TemplateDeclaration td;
     FuncDeclaration fd;
 
-    extern (D) this(const ref Loc loc, TemplateDeclaration td, FuncDeclaration fd = null)
+    extern (D) this(const ref Loc loc, TemplateDeclaration td, FuncDeclaration fd = null) @safe
     {
         super(loc, EXP.template_);
         //printf("TemplateExp(): %s\n", td.toChars());
@@ -3705,7 +3708,7 @@ extern (C++) final class NewExp : Expression
     /// The fields are still separate for backwards compatibility
     extern (D) ArgumentList argumentList() { return ArgumentList(arguments, names); }
 
-    extern (D) this(const ref Loc loc, Expression thisexp, Type newtype, Expressions* arguments, Identifiers* names = null)
+    extern (D) this(const ref Loc loc, Expression thisexp, Type newtype, Expressions* arguments, Identifiers* names = null) @safe
     {
         super(loc, EXP.new_);
         this.thisexp = thisexp;
@@ -3714,7 +3717,7 @@ extern (C++) final class NewExp : Expression
         this.names = names;
     }
 
-    static NewExp create(const ref Loc loc, Expression thisexp, Type newtype, Expressions* arguments)
+    static NewExp create(const ref Loc loc, Expression thisexp, Type newtype, Expressions* arguments) @safe
     {
         return new NewExp(loc, thisexp, newtype, arguments);
     }
@@ -3743,7 +3746,7 @@ extern (C++) final class NewAnonClassExp : Expression
     ClassDeclaration cd;    // class being instantiated
     Expressions* arguments; // Array of Expression's to call class constructor
 
-    extern (D) this(const ref Loc loc, Expression thisexp, ClassDeclaration cd, Expressions* arguments)
+    extern (D) this(const ref Loc loc, Expression thisexp, ClassDeclaration cd, Expressions* arguments) @safe
     {
         super(loc, EXP.newAnonymousClass);
         this.thisexp = thisexp;
@@ -3770,7 +3773,7 @@ extern (C++) class SymbolExp : Expression
     Dsymbol originalScope; // original scope before inlining
     bool hasOverloads;
 
-    extern (D) this(const ref Loc loc, EXP op, Declaration var, bool hasOverloads)
+    extern (D) this(const ref Loc loc, EXP op, Declaration var, bool hasOverloads) @safe
     {
         super(loc, op);
         assert(var);
@@ -3798,7 +3801,11 @@ extern (C++) final class SymOffExp : SymbolExp
             // FIXME: This error report will never be handled anyone.
             // It should be done before the SymOffExp construction.
             if (v.needThis())
-                .error(loc, "need `this` for address of `%s`", v.toChars());
+            {
+                auto t = v.isThis();
+                assert(t);
+                .error(loc, "taking the address of non-static variable `%s` requires an instance of `%s`", v.toChars(), t.toChars());
+            }
             hasOverloads = false;
         }
         super(loc, EXP.symbolOffset, var, hasOverloads);
@@ -3822,7 +3829,7 @@ extern (C++) final class SymOffExp : SymbolExp
 extern (C++) final class VarExp : SymbolExp
 {
     bool delegateWasExtracted;
-    extern (D) this(const ref Loc loc, Declaration var, bool hasOverloads = true)
+    extern (D) this(const ref Loc loc, Declaration var, bool hasOverloads = true) @safe
     {
         if (var.isVarDeclaration())
             hasOverloads = false;
@@ -3833,7 +3840,7 @@ extern (C++) final class VarExp : SymbolExp
         this.type = var.type;
     }
 
-    static VarExp create(const ref Loc loc, Declaration var, bool hasOverloads = true)
+    static VarExp create(const ref Loc loc, Declaration var, bool hasOverloads = true) @safe
     {
         return new VarExp(loc, var, hasOverloads);
     }
@@ -4242,7 +4249,7 @@ extern (C++) final class DeclarationExp : Expression
 {
     Dsymbol declaration;
 
-    extern (D) this(const ref Loc loc, Dsymbol declaration)
+    extern (D) this(const ref Loc loc, Dsymbol declaration) @safe
     {
         super(loc, EXP.declaration);
         this.declaration = declaration;
@@ -4275,7 +4282,7 @@ extern (C++) final class TypeidExp : Expression
 {
     RootObject obj;
 
-    extern (D) this(const ref Loc loc, RootObject o)
+    extern (D) this(const ref Loc loc, RootObject o) @safe
     {
         super(loc, EXP.typeid_);
         this.obj = o;
@@ -4300,7 +4307,7 @@ extern (C++) final class TraitsExp : Expression
     Identifier ident;
     Objects* args;
 
-    extern (D) this(const ref Loc loc, Identifier ident, Objects* args)
+    extern (D) this(const ref Loc loc, Identifier ident, Objects* args) @safe
     {
         super(loc, EXP.traits);
         this.ident = ident;
@@ -4325,7 +4332,7 @@ extern (C++) final class TraitsExp : Expression
  */
 extern (C++) final class HaltExp : Expression
 {
-    extern (D) this(const ref Loc loc)
+    extern (D) this(const ref Loc loc) @safe
     {
         super(loc, EXP.halt);
     }
@@ -4349,7 +4356,7 @@ extern (C++) final class IsExp : Expression
     TOK tok;            // ':' or '=='
     TOK tok2;           // 'struct', 'union', etc.
 
-    extern (D) this(const ref Loc loc, Type targ, Identifier id, TOK tok, Type tspec, TOK tok2, TemplateParameters* parameters) scope
+    extern (D) this(const ref Loc loc, Type targ, Identifier id, TOK tok, Type tspec, TOK tok2, TemplateParameters* parameters) scope @safe
     {
         super(loc, EXP.is_);
         this.targ = targ;
@@ -4388,7 +4395,7 @@ extern (C++) abstract class UnaExp : Expression
 {
     Expression e1;
 
-    extern (D) this(const ref Loc loc, EXP op, Expression e1) scope
+    extern (D) this(const ref Loc loc, EXP op, Expression e1) scope @safe
     {
         super(loc, op);
         this.e1 = e1;
@@ -4461,7 +4468,7 @@ extern (C++) abstract class BinExp : Expression
     Type att1;      // Save alias this type to detect recursion
     Type att2;      // Save alias this type to detect recursion
 
-    extern (D) this(const ref Loc loc, EXP op, Expression e1, Expression e2) scope
+    extern (D) this(const ref Loc loc, EXP op, Expression e1, Expression e2) scope @safe
     {
         super(loc, op);
         this.e1 = e1;
@@ -4752,7 +4759,7 @@ extern (C++) abstract class BinExp : Expression
  */
 extern (C++) class BinAssignExp : BinExp
 {
-    extern (D) this(const ref Loc loc, EXP op, Expression e1, Expression e2) scope
+    extern (D) this(const ref Loc loc, EXP op, Expression e1, Expression e2) scope @safe
     {
         super(loc, op, e1, e2);
     }
@@ -4789,7 +4796,7 @@ extern (C++) final class MixinExp : Expression
 {
     Expressions* exps;
 
-    extern (D) this(const ref Loc loc, Expressions* exps)
+    extern (D) this(const ref Loc loc, Expressions* exps) @safe
     {
         super(loc, EXP.mixin_);
         this.exps = exps;
@@ -4837,7 +4844,7 @@ extern (C++) final class MixinExp : Expression
  */
 extern (C++) final class ImportExp : UnaExp
 {
-    extern (D) this(const ref Loc loc, Expression e)
+    extern (D) this(const ref Loc loc, Expression e) @safe
     {
         super(loc, EXP.import_, e);
     }
@@ -4857,7 +4864,7 @@ extern (C++) final class AssertExp : UnaExp
 {
     Expression msg;
 
-    extern (D) this(const ref Loc loc, Expression e, Expression msg = null)
+    extern (D) this(const ref Loc loc, Expression e, Expression msg = null) @safe
     {
         super(loc, EXP.assert_, e);
         this.msg = msg;
@@ -4908,13 +4915,13 @@ extern (C++) final class DotIdExp : UnaExp
     bool wantsym;       // do not replace Symbol with its initializer during semantic()
     bool arrow;         // ImportC: if -> instead of .
 
-    extern (D) this(const ref Loc loc, Expression e, Identifier ident)
+    extern (D) this(const ref Loc loc, Expression e, Identifier ident) @safe
     {
         super(loc, EXP.dotIdentifier, e);
         this.ident = ident;
     }
 
-    static DotIdExp create(const ref Loc loc, Expression e, Identifier ident)
+    static DotIdExp create(const ref Loc loc, Expression e, Identifier ident) @safe
     {
         return new DotIdExp(loc, e, ident);
     }
@@ -4932,7 +4939,7 @@ extern (C++) final class DotTemplateExp : UnaExp
 {
     TemplateDeclaration td;
 
-    extern (D) this(const ref Loc loc, Expression e, TemplateDeclaration td)
+    extern (D) this(const ref Loc loc, Expression e, TemplateDeclaration td) @safe
     {
         super(loc, EXP.dotTemplateDeclaration, e);
         this.td = td;
@@ -4963,7 +4970,7 @@ extern (C++) final class DotVarExp : UnaExp
     Declaration var;
     bool hasOverloads;
 
-    extern (D) this(const ref Loc loc, Expression e, Declaration var, bool hasOverloads = true)
+    extern (D) this(const ref Loc loc, Expression e, Declaration var, bool hasOverloads = true) @safe
     {
         if (var.isVarDeclaration())
             hasOverloads = false;
@@ -5054,7 +5061,7 @@ extern (C++) final class DotTemplateInstanceExp : UnaExp
         this.ti = new TemplateInstance(loc, name, tiargs);
     }
 
-    extern (D) this(const ref Loc loc, Expression e, TemplateInstance ti)
+    extern (D) this(const ref Loc loc, Expression e, TemplateInstance ti) @safe
     {
         super(loc, EXP.dotTemplateInstance, e);
         this.ti = ti;
@@ -5147,7 +5154,7 @@ extern (C++) final class DelegateExp : UnaExp
     bool hasOverloads;
     VarDeclaration vthis2;  // container for multi-context
 
-    extern (D) this(const ref Loc loc, Expression e, FuncDeclaration f, bool hasOverloads = true, VarDeclaration vthis2 = null)
+    extern (D) this(const ref Loc loc, Expression e, FuncDeclaration f, bool hasOverloads = true, VarDeclaration vthis2 = null) @safe
     {
         super(loc, EXP.delegate_, e);
         this.func = f;
@@ -5167,7 +5174,7 @@ extern (C++) final class DotTypeExp : UnaExp
 {
     Dsymbol sym;        // symbol that represents a type
 
-    extern (D) this(const ref Loc loc, Expression e, Dsymbol s)
+    extern (D) this(const ref Loc loc, Expression e, Dsymbol s) @safe
     {
         super(loc, EXP.dotType, e);
         this.sym = s;
@@ -5222,14 +5229,14 @@ extern (C++) final class CallExp : UnaExp
     /// The fields are still separate for backwards compatibility
     extern (D) ArgumentList argumentList() { return ArgumentList(arguments, names); }
 
-    extern (D) this(const ref Loc loc, Expression e, Expressions* exps, Identifiers* names = null)
+    extern (D) this(const ref Loc loc, Expression e, Expressions* exps, Identifiers* names = null) @safe
     {
         super(loc, EXP.call, e);
         this.arguments = exps;
         this.names = names;
     }
 
-    extern (D) this(const ref Loc loc, Expression e)
+    extern (D) this(const ref Loc loc, Expression e) @safe
     {
         super(loc, EXP.call, e);
     }
@@ -5264,12 +5271,12 @@ extern (C++) final class CallExp : UnaExp
         this.f = fd;
     }
 
-    static CallExp create(const ref Loc loc, Expression e, Expressions* exps)
+    static CallExp create(const ref Loc loc, Expression e, Expressions* exps) @safe
     {
         return new CallExp(loc, e, exps);
     }
 
-    static CallExp create(const ref Loc loc, Expression e)
+    static CallExp create(const ref Loc loc, Expression e) @safe
     {
         return new CallExp(loc, e);
     }
@@ -5377,7 +5384,7 @@ TypeFunction calledFunctionType(CallExp ce)
         return null;
 }
 
-FuncDeclaration isFuncAddress(Expression e, bool* hasOverloads = null)
+FuncDeclaration isFuncAddress(Expression e, bool* hasOverloads = null) @safe
 {
     if (auto ae = e.isAddrExp())
     {
@@ -5418,12 +5425,12 @@ FuncDeclaration isFuncAddress(Expression e, bool* hasOverloads = null)
  */
 extern (C++) final class AddrExp : UnaExp
 {
-    extern (D) this(const ref Loc loc, Expression e)
+    extern (D) this(const ref Loc loc, Expression e) @safe
     {
         super(loc, EXP.address, e);
     }
 
-    extern (D) this(const ref Loc loc, Expression e, Type t)
+    extern (D) this(const ref Loc loc, Expression e, Type t) @safe
     {
         this(loc, e);
         type = t;
@@ -5440,14 +5447,14 @@ extern (C++) final class AddrExp : UnaExp
  */
 extern (C++) final class PtrExp : UnaExp
 {
-    extern (D) this(const ref Loc loc, Expression e)
+    extern (D) this(const ref Loc loc, Expression e) @safe
     {
         super(loc, EXP.star, e);
         //if (e.type)
         //  type = ((TypePointer *)e.type).next;
     }
 
-    extern (D) this(const ref Loc loc, Expression e, Type t)
+    extern (D) this(const ref Loc loc, Expression e, Type t) @safe
     {
         super(loc, EXP.star, e);
         type = t;
@@ -5493,7 +5500,7 @@ extern (C++) final class PtrExp : UnaExp
  */
 extern (C++) final class NegExp : UnaExp
 {
-    extern (D) this(const ref Loc loc, Expression e)
+    extern (D) this(const ref Loc loc, Expression e) @safe
     {
         super(loc, EXP.negate, e);
     }
@@ -5509,7 +5516,7 @@ extern (C++) final class NegExp : UnaExp
  */
 extern (C++) final class UAddExp : UnaExp
 {
-    extern (D) this(const ref Loc loc, Expression e) scope
+    extern (D) this(const ref Loc loc, Expression e) scope @safe
     {
         super(loc, EXP.uadd, e);
     }
@@ -5525,7 +5532,7 @@ extern (C++) final class UAddExp : UnaExp
  */
 extern (C++) final class ComExp : UnaExp
 {
-    extern (D) this(const ref Loc loc, Expression e)
+    extern (D) this(const ref Loc loc, Expression e) @safe
     {
         super(loc, EXP.tilde, e);
     }
@@ -5541,7 +5548,7 @@ extern (C++) final class ComExp : UnaExp
  */
 extern (C++) final class NotExp : UnaExp
 {
-    extern (D) this(const ref Loc loc, Expression e)
+    extern (D) this(const ref Loc loc, Expression e) @safe
     {
         super(loc, EXP.not, e);
     }
@@ -5561,7 +5568,7 @@ extern (C++) final class DeleteExp : UnaExp
 {
     bool isRAII;        // true if called automatically as a result of scoped destruction
 
-    extern (D) this(const ref Loc loc, Expression e, bool isRAII)
+    extern (D) this(const ref Loc loc, Expression e, bool isRAII) @safe
     {
         super(loc, EXP.delete_, e);
         this.isRAII = isRAII;
@@ -5585,7 +5592,7 @@ extern (C++) final class CastExp : UnaExp
     Type to;                    // type to cast to
     ubyte mod = cast(ubyte)~0;  // MODxxxxx
 
-    extern (D) this(const ref Loc loc, Expression e, Type t)
+    extern (D) this(const ref Loc loc, Expression e, Type t) @safe
     {
         super(loc, EXP.cast_, e);
         this.to = t;
@@ -5593,7 +5600,7 @@ extern (C++) final class CastExp : UnaExp
 
     /* For cast(const) and cast(immutable)
      */
-    extern (D) this(const ref Loc loc, Expression e, ubyte mod)
+    extern (D) this(const ref Loc loc, Expression e, ubyte mod) @safe
     {
         super(loc, EXP.cast_, e);
         this.mod = mod;
@@ -5647,14 +5654,14 @@ extern (C++) final class VectorExp : UnaExp
     uint dim = ~0;      // number of elements in the vector
     OwnedBy ownedByCtfe = OwnedBy.code;
 
-    extern (D) this(const ref Loc loc, Expression e, Type t)
+    extern (D) this(const ref Loc loc, Expression e, Type t) @safe
     {
         super(loc, EXP.vector, e);
         assert(t.ty == Tvector);
         to = cast(TypeVector)t;
     }
 
-    static VectorExp create(const ref Loc loc, Expression e, Type t)
+    static VectorExp create(const ref Loc loc, Expression e, Type t) @safe
     {
         return new VectorExp(loc, e, t);
     }
@@ -5683,7 +5690,7 @@ extern (C++) final class VectorExp : UnaExp
  */
 extern (C++) final class VectorArrayExp : UnaExp
 {
-    extern (D) this(const ref Loc loc, Expression e1)
+    extern (D) this(const ref Loc loc, Expression e1) @safe
     {
         super(loc, EXP.vectorArray, e1);
     }
@@ -5727,14 +5734,14 @@ extern (C++) final class SliceExp : UnaExp
     mixin(generateBitFields!(BitFields, ubyte));
 
     /************************************************************/
-    extern (D) this(const ref Loc loc, Expression e1, IntervalExp ie)
+    extern (D) this(const ref Loc loc, Expression e1, IntervalExp ie) @safe
     {
         super(loc, EXP.slice, e1);
         this.upr = ie ? ie.upr : null;
         this.lwr = ie ? ie.lwr : null;
     }
 
-    extern (D) this(const ref Loc loc, Expression e1, Expression lwr, Expression upr)
+    extern (D) this(const ref Loc loc, Expression e1, Expression lwr, Expression upr) @safe
     {
         super(loc, EXP.slice, e1);
         this.upr = upr;
@@ -5784,7 +5791,7 @@ extern (C++) final class SliceExp : UnaExp
  */
 extern (C++) final class ArrayLengthExp : UnaExp
 {
-    extern (D) this(const ref Loc loc, Expression e1)
+    extern (D) this(const ref Loc loc, Expression e1) @safe
     {
         super(loc, EXP.arrayLength, e1);
     }
@@ -5815,7 +5822,7 @@ extern (C++) final class ArrayExp : UnaExp
             arguments.push(index);
     }
 
-    extern (D) this(const ref Loc loc, Expression e1, Expressions* args)
+    extern (D) this(const ref Loc loc, Expression e1, Expressions* args) @safe
     {
         super(loc, EXP.array, e1);
         arguments = args;
@@ -5852,7 +5859,7 @@ extern (C++) final class ArrayExp : UnaExp
  */
 extern (C++) final class DotExp : BinExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.dot, e1, e2);
     }
@@ -5878,7 +5885,7 @@ extern (C++) final class CommaExp : BinExp
     bool allowCommaExp;
 
 
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2, bool generated = true)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2, bool generated = true) @safe
     {
         super(loc, EXP.comma, e1, e2);
         allowCommaExp = isGenerated = generated;
@@ -5931,7 +5938,7 @@ extern (C++) final class CommaExp : BinExp
      *   exp = An expression that discards its result.
      *         If the argument is null or not a CommaExp, nothing happens.
      */
-    static void allow(Expression exp)
+    static void allow(Expression exp) @safe
     {
         if (exp)
             if (auto ce = exp.isCommaExp())
@@ -5947,7 +5954,7 @@ extern (C++) final class IntervalExp : Expression
     Expression lwr;
     Expression upr;
 
-    extern (D) this(const ref Loc loc, Expression lwr, Expression upr)
+    extern (D) this(const ref Loc loc, Expression lwr, Expression upr) @safe
     {
         super(loc, EXP.interval);
         this.lwr = lwr;
@@ -5972,7 +5979,7 @@ extern (C++) final class IntervalExp : Expression
  */
 extern (C++) final class DelegatePtrExp : UnaExp
 {
-    extern (D) this(const ref Loc loc, Expression e1)
+    extern (D) this(const ref Loc loc, Expression e1) @safe
     {
         super(loc, EXP.delegatePointer, e1);
     }
@@ -6010,7 +6017,7 @@ extern (C++) final class DelegatePtrExp : UnaExp
  */
 extern (C++) final class DelegateFuncptrExp : UnaExp
 {
-    extern (D) this(const ref Loc loc, Expression e1)
+    extern (D) this(const ref Loc loc, Expression e1) @safe
     {
         super(loc, EXP.delegateFunctionPointer, e1);
     }
@@ -6050,13 +6057,13 @@ extern (C++) final class IndexExp : BinExp
     bool modifiable = false;    // assume it is an rvalue
     bool indexIsInBounds;       // true if 0 <= e2 && e2 <= e1.length - 1
 
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.index, e1, e2);
         //printf("IndexExp::IndexExp('%s')\n", toChars());
     }
 
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2, bool indexIsInBounds)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2, bool indexIsInBounds) @safe
     {
         super(loc, EXP.index, e1, e2);
         this.indexIsInBounds = indexIsInBounds;
@@ -6150,7 +6157,7 @@ extern (C++) final class PostExp : BinExp
  */
 extern (C++) final class PreExp : UnaExp
 {
-    extern (D) this(EXP op, const ref Loc loc, Expression e)
+    extern (D) this(EXP op, const ref Loc loc, Expression e) @safe
     {
         super(loc, op, e);
         assert(op == EXP.preMinusMinus || op == EXP.prePlusPlus);
@@ -6180,12 +6187,12 @@ extern (C++) class AssignExp : BinExp
 
     /************************************************************/
     /* op can be EXP.assign, EXP.construct, or EXP.blit */
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.assign, e1, e2);
     }
 
-    this(const ref Loc loc, EXP tok, Expression e1, Expression e2)
+    this(const ref Loc loc, EXP tok, Expression e1, Expression e2) @safe
     {
         super(loc, tok, e1, e2);
     }
@@ -6231,7 +6238,7 @@ extern (C++) class AssignExp : BinExp
 extern (C++) final class LoweredAssignExp : AssignExp
 {
     Expression lowering;
-    extern (D) this(AssignExp exp, Expression lowering)
+    extern (D) this(AssignExp exp, Expression lowering) @safe
     {
         super(exp.loc, EXP.loweredAssignExp, exp.e1, exp.e2);
         this.lowering = lowering;
@@ -6251,14 +6258,14 @@ extern (C++) final class LoweredAssignExp : AssignExp
  */
 extern (C++) final class ConstructExp : AssignExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.construct, e1, e2);
     }
 
     // Internal use only. If `v` is a reference variable, the assignment
     // will become a reference initialization automatically.
-    extern (D) this(const ref Loc loc, VarDeclaration v, Expression e2)
+    extern (D) this(const ref Loc loc, VarDeclaration v, Expression e2) @safe
     {
         auto ve = new VarExp(loc, v);
         assert(v.type && ve.type);
@@ -6280,14 +6287,14 @@ extern (C++) final class ConstructExp : AssignExp
  */
 extern (C++) final class BlitExp : AssignExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.blit, e1, e2);
     }
 
     // Internal use only. If `v` is a reference variable, the assinment
     // will become a reference rebinding automatically.
-    extern (D) this(const ref Loc loc, VarDeclaration v, Expression e2)
+    extern (D) this(const ref Loc loc, VarDeclaration v, Expression e2) @safe
     {
         auto ve = new VarExp(loc, v);
         assert(v.type && ve.type);
@@ -6309,7 +6316,7 @@ extern (C++) final class BlitExp : AssignExp
  */
 extern (C++) final class AddAssignExp : BinAssignExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.addAssign, e1, e2);
     }
@@ -6325,7 +6332,7 @@ extern (C++) final class AddAssignExp : BinAssignExp
  */
 extern (C++) final class MinAssignExp : BinAssignExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.minAssign, e1, e2);
     }
@@ -6341,7 +6348,7 @@ extern (C++) final class MinAssignExp : BinAssignExp
  */
 extern (C++) final class MulAssignExp : BinAssignExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.mulAssign, e1, e2);
     }
@@ -6357,7 +6364,7 @@ extern (C++) final class MulAssignExp : BinAssignExp
  */
 extern (C++) final class DivAssignExp : BinAssignExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.divAssign, e1, e2);
     }
@@ -6373,7 +6380,7 @@ extern (C++) final class DivAssignExp : BinAssignExp
  */
 extern (C++) final class ModAssignExp : BinAssignExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.modAssign, e1, e2);
     }
@@ -6389,7 +6396,7 @@ extern (C++) final class ModAssignExp : BinAssignExp
  */
 extern (C++) final class AndAssignExp : BinAssignExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.andAssign, e1, e2);
     }
@@ -6405,7 +6412,7 @@ extern (C++) final class AndAssignExp : BinAssignExp
  */
 extern (C++) final class OrAssignExp : BinAssignExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.orAssign, e1, e2);
     }
@@ -6421,7 +6428,7 @@ extern (C++) final class OrAssignExp : BinAssignExp
  */
 extern (C++) final class XorAssignExp : BinAssignExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.xorAssign, e1, e2);
     }
@@ -6437,7 +6444,7 @@ extern (C++) final class XorAssignExp : BinAssignExp
  */
 extern (C++) final class PowAssignExp : BinAssignExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.powAssign, e1, e2);
     }
@@ -6453,7 +6460,7 @@ extern (C++) final class PowAssignExp : BinAssignExp
  */
 extern (C++) final class ShlAssignExp : BinAssignExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.leftShiftAssign, e1, e2);
     }
@@ -6469,7 +6476,7 @@ extern (C++) final class ShlAssignExp : BinAssignExp
  */
 extern (C++) final class ShrAssignExp : BinAssignExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.rightShiftAssign, e1, e2);
     }
@@ -6485,7 +6492,7 @@ extern (C++) final class ShrAssignExp : BinAssignExp
  */
 extern (C++) final class UshrAssignExp : BinAssignExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.unsignedRightShiftAssign, e1, e2);
     }
@@ -6510,12 +6517,12 @@ extern (C++) final class UshrAssignExp : BinAssignExp
  */
 extern (C++) class CatAssignExp : BinAssignExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.concatenateAssign, e1, e2);
     }
 
-    extern (D) this(const ref Loc loc, EXP tok, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, EXP tok, Expression e1, Expression e2) @safe
     {
         super(loc, tok, e1, e2);
     }
@@ -6531,7 +6538,7 @@ extern (C++) class CatAssignExp : BinAssignExp
  */
 extern (C++) final class CatElemAssignExp : CatAssignExp
 {
-    extern (D) this(const ref Loc loc, Type type, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Type type, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.concatenateElemAssign, e1, e2);
         this.type = type;
@@ -6548,7 +6555,7 @@ extern (C++) final class CatElemAssignExp : CatAssignExp
  */
 extern (C++) final class CatDcharAssignExp : CatAssignExp
 {
-    extern (D) this(const ref Loc loc, Type type, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Type type, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.concatenateDcharAssign, e1, e2);
         this.type = type;
@@ -6567,7 +6574,7 @@ extern (C++) final class CatDcharAssignExp : CatAssignExp
  */
 extern (C++) final class AddExp : BinExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.add, e1, e2);
     }
@@ -6585,7 +6592,7 @@ extern (C++) final class AddExp : BinExp
  */
 extern (C++) final class MinExp : BinExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.min, e1, e2);
     }
@@ -6605,7 +6612,7 @@ extern (C++) final class CatExp : BinExp
 {
     Expression lowering;  // call to druntime hook `_d_arraycatnTX`
 
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2) scope
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) scope @safe
     {
         super(loc, EXP.concatenate, e1, e2);
     }
@@ -6630,7 +6637,7 @@ extern (C++) final class CatExp : BinExp
  */
 extern (C++) final class MulExp : BinExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.mul, e1, e2);
     }
@@ -6648,7 +6655,7 @@ extern (C++) final class MulExp : BinExp
  */
 extern (C++) final class DivExp : BinExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.div, e1, e2);
     }
@@ -6666,7 +6673,7 @@ extern (C++) final class DivExp : BinExp
  */
 extern (C++) final class ModExp : BinExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.mod, e1, e2);
     }
@@ -6684,7 +6691,7 @@ extern (C++) final class ModExp : BinExp
  */
 extern (C++) final class PowExp : BinExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.pow, e1, e2);
     }
@@ -6702,7 +6709,7 @@ extern (C++) final class PowExp : BinExp
  */
 extern (C++) final class ShlExp : BinExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.leftShift, e1, e2);
     }
@@ -6720,7 +6727,7 @@ extern (C++) final class ShlExp : BinExp
  */
 extern (C++) final class ShrExp : BinExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.rightShift, e1, e2);
     }
@@ -6738,7 +6745,7 @@ extern (C++) final class ShrExp : BinExp
  */
 extern (C++) final class UshrExp : BinExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.unsignedRightShift, e1, e2);
     }
@@ -6756,7 +6763,7 @@ extern (C++) final class UshrExp : BinExp
  */
 extern (C++) final class AndExp : BinExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.and, e1, e2);
     }
@@ -6774,7 +6781,7 @@ extern (C++) final class AndExp : BinExp
  */
 extern (C++) final class OrExp : BinExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.or, e1, e2);
     }
@@ -6792,7 +6799,7 @@ extern (C++) final class OrExp : BinExp
  */
 extern (C++) final class XorExp : BinExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.xor, e1, e2);
     }
@@ -6811,7 +6818,7 @@ extern (C++) final class XorExp : BinExp
  */
 extern (C++) final class LogicalExp : BinExp
 {
-    extern (D) this(const ref Loc loc, EXP op, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, EXP op, Expression e1, Expression e2) @safe
     {
         super(loc, op, e1, e2);
         assert(op == EXP.andAnd || op == EXP.orOr);
@@ -6833,7 +6840,7 @@ extern (C++) final class LogicalExp : BinExp
  */
 extern (C++) final class CmpExp : BinExp
 {
-    extern (D) this(EXP op, const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(EXP op, const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, op, e1, e2);
         assert(op == EXP.lessThan || op == EXP.lessOrEqual || op == EXP.greaterThan || op == EXP.greaterOrEqual);
@@ -6854,7 +6861,7 @@ extern (C++) final class CmpExp : BinExp
  */
 extern (C++) final class InExp : BinExp
 {
-    extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, EXP.in_, e1, e2);
     }
@@ -6893,7 +6900,7 @@ extern (C++) final class RemoveExp : BinExp
  */
 extern (C++) final class EqualExp : BinExp
 {
-    extern (D) this(EXP op, const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(EXP op, const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, op, e1, e2);
         assert(op == EXP.equal || op == EXP.notEqual);
@@ -6914,7 +6921,7 @@ extern (C++) final class EqualExp : BinExp
  */
 extern (C++) final class IdentityExp : BinExp
 {
-    extern (D) this(EXP op, const ref Loc loc, Expression e1, Expression e2)
+    extern (D) this(EXP op, const ref Loc loc, Expression e1, Expression e2) @safe
     {
         super(loc, op, e1, e2);
         assert(op == EXP.identity || op == EXP.notIdentity);
@@ -6935,7 +6942,7 @@ extern (C++) final class CondExp : BinExp
 {
     Expression econd;
 
-    extern (D) this(const ref Loc loc, Expression econd, Expression e1, Expression e2) scope
+    extern (D) this(const ref Loc loc, Expression econd, Expression e1, Expression e2) scope @safe
     {
         super(loc, EXP.question, e1, e2);
         this.econd = econd;
@@ -6984,7 +6991,7 @@ extern (C++) final class CondExp : BinExp
             VarDeclaration vcond;
             bool isThen;
 
-            extern (D) this(Scope* sc, CondExp ce)
+            extern (D) this(Scope* sc, CondExp ce) @safe
             {
                 this.sc = sc;
                 this.ce = ce;
@@ -7075,7 +7082,7 @@ bool isDefaultInitOp(EXP op) pure nothrow @safe @nogc
  */
 extern (C++) class DefaultInitExp : Expression
 {
-    extern (D) this(const ref Loc loc, EXP op)
+    extern (D) this(const ref Loc loc, EXP op) @safe
     {
         super(loc, op);
     }
@@ -7091,7 +7098,7 @@ extern (C++) class DefaultInitExp : Expression
  */
 extern (C++) final class FileInitExp : DefaultInitExp
 {
-    extern (D) this(const ref Loc loc, EXP tok)
+    extern (D) this(const ref Loc loc, EXP tok) @safe
     {
         super(loc, tok);
     }
@@ -7120,7 +7127,7 @@ extern (C++) final class FileInitExp : DefaultInitExp
  */
 extern (C++) final class LineInitExp : DefaultInitExp
 {
-    extern (D) this(const ref Loc loc)
+    extern (D) this(const ref Loc loc) @safe
     {
         super(loc, EXP.line);
     }
@@ -7142,7 +7149,7 @@ extern (C++) final class LineInitExp : DefaultInitExp
  */
 extern (C++) final class ModuleInitExp : DefaultInitExp
 {
-    extern (D) this(const ref Loc loc)
+    extern (D) this(const ref Loc loc) @safe
     {
         super(loc, EXP.moduleString);
     }
@@ -7165,7 +7172,7 @@ extern (C++) final class ModuleInitExp : DefaultInitExp
  */
 extern (C++) final class FuncInitExp : DefaultInitExp
 {
-    extern (D) this(const ref Loc loc)
+    extern (D) this(const ref Loc loc) @safe
     {
         super(loc, EXP.functionString);
     }
@@ -7194,7 +7201,7 @@ extern (C++) final class FuncInitExp : DefaultInitExp
  */
 extern (C++) final class PrettyFuncInitExp : DefaultInitExp
 {
-    extern (D) this(const ref Loc loc)
+    extern (D) this(const ref Loc loc) @safe
     {
         super(loc, EXP.prettyFunction);
     }
@@ -7262,7 +7269,7 @@ extern (C++) final class GenericExp : Expression
     Types* types;       /// type-names for generic associations (null entry for `default`)
     Expressions* exps;  /// 1:1 mapping of typeNames to exps
 
-    extern (D) this(const ref Loc loc, Expression cntlExp, Types* types, Expressions* exps)
+    extern (D) this(const ref Loc loc, Expression cntlExp, Types* types, Expressions* exps) @safe
     {
         super(loc, EXP._Generic);
         this.cntlExp = cntlExp;
diff --git a/gcc/d/dmd/expression.h b/gcc/d/dmd/expression.h
index 8c6393fb6e1..1f04c6cb1db 100644
--- a/gcc/d/dmd/expression.h
+++ b/gcc/d/dmd/expression.h
@@ -955,6 +955,7 @@ public:
 private:
     uint8_t bitFields;
 
+public:
     SliceExp *syntaxCopy() override;
     bool isLvalue() override;
     Expression *toLvalue(Scope *sc, Expression *e) override;
diff --git a/gcc/d/dmd/expressionsem.d b/gcc/d/dmd/expressionsem.d
index 25f755bdf0e..69999cbf32a 100644
--- a/gcc/d/dmd/expressionsem.d
+++ b/gcc/d/dmd/expressionsem.d
@@ -875,6 +875,13 @@ Lagain:
                 if (sc.setUnsafePreview(global.params.systemVariables, false, loc,
                     "cannot access `@system` variable `%s` in @safe code", sd))
                 {
+                    if (auto v = sd.isVarDeclaration())
+                    {
+                        if (v.systemInferred)
+                            errorSupplemental(v.loc, "`%s` is inferred to be `@system` from its initializer here", v.toChars());
+                        else
+                            errorSupplemental(v.loc, "`%s` is declared here", v.toChars());
+                    }
                     return ErrorExp.get();
                 }
             }
@@ -1582,7 +1589,7 @@ private Type arrayExpressionToCommonType(Scope* sc, ref Expressions exps)
     return t0;
 }
 
-private Expression opAssignToOp(const ref Loc loc, EXP op, Expression e1, Expression e2)
+private Expression opAssignToOp(const ref Loc loc, EXP op, Expression e1, Expression e2) @safe
 {
     Expression e;
     switch (op)
@@ -2609,7 +2616,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
     Scope* sc;
     Expression result;
 
-    this(Scope* sc) scope
+    this(Scope* sc) scope @safe
     {
         this.sc = sc;
     }
@@ -2619,6 +2626,14 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
         result = ErrorExp.get();
     }
 
+    private void needThisError(Loc loc, FuncDeclaration f)
+    {
+        auto t = f.isThis();
+        assert(t);
+        .error(loc, "calling non-static function `%s` requires an instance of type `%s`", f.toChars(), t.toChars());
+        setError();
+    }
+
     /**************************
      * Semantically analyze Expression.
      * Determine types, fold constants, etc.
@@ -3721,12 +3736,13 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
             if (cd.isAbstract())
             {
                 exp.error("cannot create instance of abstract class `%s`", cd.toChars());
+                errorSupplemental(cd.loc, "class `%s` is declared here", cd.toChars());
                 for (size_t i = 0; i < cd.vtbl.length; i++)
                 {
                     FuncDeclaration fd = cd.vtbl[i].isFuncDeclaration();
                     if (fd && fd.isAbstract())
                     {
-                        errorSupplemental(exp.loc, "function `%s` is not implemented",
+                        errorSupplemental(fd.loc, "function `%s` is not implemented",
                             fd.toFullSignature());
                     }
                 }
@@ -5242,8 +5258,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
                     }
                     else if (isNeedThisScope(sc, exp.f))
                     {
-                        exp.error("need `this` for `%s` of type `%s`", exp.f.toChars(), exp.f.type.toChars());
-                        return setError();
+                        return needThisError(exp.loc, exp.f);
                     }
                 }
                 exp.e1 = new VarExp(exp.e1.loc, exp.f, false);
@@ -5386,8 +5401,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
 
                     // If no error is printed, it means that `f` is the single matching overload
                     // and it needs `this`.
-                    exp.error("need `this` for `%s` of type `%s`", exp.f.toChars(), exp.f.type.toChars());
-                    return setError();
+                    return needThisError(exp.loc, exp.f);
                 }
             }
 
@@ -5958,18 +5972,20 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
                 break;
 
             case TOK.function_:
+                if (e.targ.ty != Tfunction)
+                    return no();
+                goto case;
             case TOK.parameters:
                 {
-                    if (e.targ.ty != Tfunction)
+                    if (auto tf = e.targ.isFunction_Delegate_PtrToFunction())
+                        tded = tf;
+                    else
                         return no();
-                    tded = e.targ;
 
                     /* Generate tuple from function parameter types.
                      */
-                    assert(tded.ty == Tfunction);
-                    auto tdedf = tded.isTypeFunction();
                     auto args = new Parameters();
-                    foreach (i, arg; tdedf.parameterList)
+                    foreach (i, arg; tded.isTypeFunction().parameterList)
                     {
                         assert(arg && arg.type);
                         /* If one of the default arguments was an error,
@@ -6267,7 +6283,10 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
 
         if (p.token.value != TOK.endOfFile)
         {
-            exp.error("incomplete mixin expression `%s`", str.ptr);
+            e.error("unexpected token `%s` after %s expression",
+                p.token.toChars(), EXPtoString(e.op).ptr);
+            e.errorSupplemental("while parsing string mixin expression `%s`",
+                str.ptr);
             return null;
         }
         return e;
@@ -6632,7 +6651,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
             else
             {
                 OutBuffer buf;
-                buf.printf("%s failed", exp.toChars());
+                buf.printf("`%s` failed", exp.toChars());
                 exp.msg = new StringExp(Loc.initial, buf.extractSlice());
                 goto LSkip;
             }
@@ -12911,7 +12930,7 @@ private Expression dotIdSemanticPropX(DotIdExp exp, Scope* sc)
                 }
             }
             OutBuffer buf;
-            mangleToBuffer(ds, &buf);
+            mangleToBuffer(ds, buf);
             Expression e = new StringExp(loc, buf.extractSlice());
             return e.expressionSemantic(sc);
         }
diff --git a/gcc/d/dmd/foreachvar.d b/gcc/d/dmd/foreachvar.d
index 1293057fe83..8af2a95252e 100644
--- a/gcc/d/dmd/foreachvar.d
+++ b/gcc/d/dmd/foreachvar.d
@@ -56,7 +56,7 @@ void foreachVar(Expression e, void delegate(VarDeclaration) dgVar)
         alias visit = typeof(super).visit;
         extern (D) void delegate(VarDeclaration) dgVar;
 
-        extern (D) this(void delegate(VarDeclaration) dgVar) scope
+        extern (D) this(void delegate(VarDeclaration) dgVar) scope @safe
         {
             this.dgVar = dgVar;
         }
diff --git a/gcc/d/dmd/func.d b/gcc/d/dmd/func.d
index 60457351af6..73f1ba786cb 100644
--- a/gcc/d/dmd/func.d
+++ b/gcc/d/dmd/func.d
@@ -2509,7 +2509,7 @@ extern (C++) class FuncDeclaration : Declaration
      * Returns:
      *      true    found an 'out' contract
      */
-    static bool needsFensure(FuncDeclaration fd)
+    static bool needsFensure(FuncDeclaration fd) @safe
     {
         if (fd.fensures)
             return true;
@@ -4558,9 +4558,10 @@ bool setUnsafe(Scope* sc,
                 .error(loc, fmt, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : "", arg2 ? arg2.toChars() : "");
                 return true;
             }
-            else if (!(sc.varDecl.storage_class & STC.system))
+            else if (!(sc.varDecl.storage_class & STC.trusted))
             {
                 sc.varDecl.storage_class |= STC.system;
+                sc.varDecl.systemInferred = true;
             }
         }
         return false;
@@ -4606,6 +4607,7 @@ bool setUnsafe(Scope* sc,
 bool setUnsafePreview(Scope* sc, FeatureState fs, bool gag, Loc loc, const(char)* msg,
     RootObject arg0 = null, RootObject arg1 = null, RootObject arg2 = null)
 {
+    //printf("setUnsafePreview() fs:%d %s\n", fs, msg);
     with (FeatureState) final switch (fs)
     {
       case disabled:
@@ -4620,9 +4622,10 @@ bool setUnsafePreview(Scope* sc, FeatureState fs, bool gag, Loc loc, const(char)
         if (sc.func.isSafeBypassingInference())
         {
             if (!gag)
-                previewErrorFunc(sc.isDeprecated(), fs)(
-                    loc, msg, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : "", arg2 ? arg2.toChars() : ""
-                );
+            {
+                if (!sc.isDeprecated() && global.params.obsolete)
+                    warning(loc, msg, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : "", arg2 ? arg2.toChars() : "");
+            }
         }
         else if (!sc.func.safetyViolation)
         {
@@ -4706,9 +4709,9 @@ void errorSupplementalInferredAttr(FuncDeclaration fd, int maxDepth, bool deprec
                     s.arg0 ? s.arg0.toChars() : "", s.arg1 ? s.arg1.toChars() : "", s.arg2 ? s.arg2.toChars() : "");
             }
         }
-        else if (s.arg0.dyncast() == DYNCAST.dsymbol)
+        else if (auto sa = s.arg0.isDsymbol())
         {
-            if (FuncDeclaration fd2 = (cast(Dsymbol) s.arg0).isFuncDeclaration())
+            if (FuncDeclaration fd2 = sa.isFuncDeclaration())
             {
                 if (maxDepth > 0)
                 {
diff --git a/gcc/d/dmd/globals.d b/gcc/d/dmd/globals.d
index 9071e6a58ca..af711a0fd0a 100644
--- a/gcc/d/dmd/globals.d
+++ b/gcc/d/dmd/globals.d
@@ -133,7 +133,7 @@ extern (C++) struct Param
     bool useModuleInfo = true;   // generate runtime module information
     bool useTypeInfo = true;     // generate runtime type information
     bool useExceptions = true;   // support exception handling
-    bool useGC = true;           // support features that require the GC
+    bool useGC = true;           // support features that require the D runtime GC
     bool betterC;           // be a "better C" compiler; no dependency on D runtime
     bool addMain;           // add a default main() function
     bool allInst;           // generate code for all template instantiations
@@ -297,7 +297,7 @@ extern (C++) struct Global
      *
      * Returns: the current number of gagged errors, which should later be passed to `endGagging`
      */
-    extern (C++) uint startGagging()
+    extern (C++) uint startGagging() @safe
     {
         ++gag;
         gaggedWarnings = 0;
@@ -311,7 +311,7 @@ extern (C++) struct Global
      *   oldGagged = the previous number of errors, as returned by `startGagging`
      * Returns: true if errors occurred while gagged.
      */
-    extern (C++) bool endGagging(uint oldGagged)
+    extern (C++) bool endGagging(uint oldGagged) @safe
     {
         bool anyErrs = (gaggedErrors != oldGagged);
         --gag;
@@ -327,7 +327,7 @@ extern (C++) struct Global
      *
      * An error message may or may not have been printed.
      */
-    extern (C++) void increaseErrorCount()
+    extern (C++) void increaseErrorCount() @safe
     {
         if (gag)
             ++gaggedErrors;
@@ -344,8 +344,8 @@ extern (C++) struct Global
             compileEnv.vendor = "Digital Mars D";
 
             // -color=auto is the default value
-            import dmd.console : detectTerminal;
-            params.color = detectTerminal();
+            import dmd.console : detectTerminal, detectColorPreference;
+            params.color = detectTerminal() && detectColorPreference();
         }
         else version (IN_GCC)
         {
@@ -397,7 +397,7 @@ extern (C++) struct Global
     /**
      * Computes the version number __VERSION__ from the compiler version string.
      */
-    extern (D) private static uint parseVersionNumber(string version_)
+    extern (D) private static uint parseVersionNumber(string version_) @safe
     {
         //
         // parse _version
@@ -429,7 +429,7 @@ extern (C++) struct Global
     /**
     Returns: the version as the number that would be returned for __VERSION__
     */
-    extern(C++) uint versionNumber()
+    extern(C++) uint versionNumber() @safe
     {
         return compileEnv.versionNumber;
     }
@@ -437,7 +437,7 @@ extern (C++) struct Global
     /**
     Returns: compiler version string.
     */
-    extern(D) string versionString()
+    extern(D) string versionString() @safe
     {
         return _version;
     }
diff --git a/gcc/d/dmd/globals.h b/gcc/d/dmd/globals.h
index 0dad5dd12e7..0ef9eed405c 100644
--- a/gcc/d/dmd/globals.h
+++ b/gcc/d/dmd/globals.h
@@ -128,7 +128,7 @@ struct Param
     d_bool useModuleInfo; // generate runtime module information
     d_bool useTypeInfo;   // generate runtime type information
     d_bool useExceptions; // support exception handling
-    d_bool useGC;         // support features that require the GC
+    d_bool useGC;         // support features that require the D runtime GC
     d_bool betterC;       // be a "better C" compiler; no dependency on D runtime
     d_bool addMain;       // add a default main() function
     d_bool allInst;       // generate code for all template instantiations
diff --git a/gcc/d/dmd/hdrgen.d b/gcc/d/dmd/hdrgen.d
index 62e0d49fdd5..33cbc19c690 100644
--- a/gcc/d/dmd/hdrgen.d
+++ b/gcc/d/dmd/hdrgen.d
@@ -805,7 +805,7 @@ public:
     OutBuffer* buf;
     HdrGenState* hgs;
 
-    extern (D) this(OutBuffer* buf, HdrGenState* hgs) scope
+    extern (D) this(OutBuffer* buf, HdrGenState* hgs) scope @safe
     {
         this.buf = buf;
         this.hgs = hgs;
@@ -2775,7 +2775,7 @@ public:
     OutBuffer* buf;
     HdrGenState* hgs;
 
-    extern (D) this(OutBuffer* buf, HdrGenState* hgs) scope
+    extern (D) this(OutBuffer* buf, HdrGenState* hgs) scope @safe
     {
         this.buf = buf;
         this.hgs = hgs;
@@ -2856,7 +2856,7 @@ public:
     OutBuffer* buf;
     HdrGenState* hgs;
 
-    extern (D) this(OutBuffer* buf, HdrGenState* hgs) scope
+    extern (D) this(OutBuffer* buf, HdrGenState* hgs) scope @safe
     {
         this.buf = buf;
         this.hgs = hgs;
@@ -2920,7 +2920,7 @@ void toCBuffer(const Initializer iz, OutBuffer* buf, HdrGenState* hgs)
     initializerToBuffer(cast() iz, buf, hgs);
 }
 
-bool stcToBuffer(OutBuffer* buf, StorageClass stc)
+bool stcToBuffer(OutBuffer* buf, StorageClass stc) @safe
 {
     //printf("stc: %llx\n", stc);
     bool result = false;
@@ -2980,7 +2980,7 @@ bool stcToBuffer(OutBuffer* buf, StorageClass stc)
  * and return a string representation of it.
  * stc is reduced by the one picked.
  */
-string stcToString(ref StorageClass stc)
+string stcToString(ref StorageClass stc) @safe
 {
     static struct SCstring
     {
@@ -3039,7 +3039,7 @@ string stcToString(ref StorageClass stc)
     return null;
 }
 
-private void linkageToBuffer(OutBuffer* buf, LINK linkage)
+private void linkageToBuffer(OutBuffer* buf, LINK linkage) @safe
 {
     const s = linkageToString(linkage);
     if (s.length)
@@ -3056,7 +3056,7 @@ const(char)* linkageToChars(LINK linkage)
     return linkageToString(linkage).ptr;
 }
 
-string linkageToString(LINK linkage) pure nothrow
+string linkageToString(LINK linkage) pure nothrow @safe
 {
     final switch (linkage)
     {
@@ -3099,7 +3099,7 @@ const(char)* visibilityToChars(Visibility.Kind kind)
 }
 
 /// Ditto
-extern (D) string visibilityToString(Visibility.Kind kind) nothrow pure
+extern (D) string visibilityToString(Visibility.Kind kind) nothrow pure @safe
 {
     final switch (kind)
     {
diff --git a/gcc/d/dmd/id.d b/gcc/d/dmd/id.d
index a2daf6064d3..43b2e5f5a50 100644
--- a/gcc/d/dmd/id.d
+++ b/gcc/d/dmd/id.d
@@ -575,7 +575,7 @@ struct Msgtable
      * Returns: the name to use in the D executable, `name_` if non-empty,
      *  otherwise `ident`
      */
-    string name()
+    string name() @safe
     {
         return name_ ? name_ : ident;
     }
@@ -602,19 +602,19 @@ string generate(immutable(Msgtable)[] msgtable, string function(Msgtable) dg)
 }
 
 // Used to generate the code for each identifier.
-string identifier(Msgtable m)
+string identifier(Msgtable m) @safe
 {
     return "Identifier " ~ m.ident ~ ";";
 }
 
 // Used to generate the code for each initializer.
-string initializer(Msgtable m)
+string initializer(Msgtable m) @safe
 {
     return m.ident ~ ` = Identifier.idPool("` ~ m.name ~ `");`;
 }
 
 // Used to generate the code for each deinitializer.
-string deinitializer(Msgtable m)
+string deinitializer(Msgtable m) @safe
 {
     return m.ident ~ " = Identifier.init;";
 }
diff --git a/gcc/d/dmd/identifier.d b/gcc/d/dmd/identifier.d
index b1c421c1c59..3173445fddc 100644
--- a/gcc/d/dmd/identifier.d
+++ b/gcc/d/dmd/identifier.d
@@ -64,13 +64,13 @@ nothrow:
     }
 
     /// ditto
-    extern (D) this(const(char)[] name, int value)
+    extern (D) this(const(char)[] name, int value) @safe
     {
         //printf("Identifier('%.*s', %d)\n", cast(int)name.length, name.ptr, value);
         this(name, value, false);
     }
 
-    extern (D) private this(const(char)[] name, int value, bool isAnonymous)
+    extern (D) private this(const(char)[] name, int value, bool isAnonymous) @safe
     {
         //printf("Identifier('%.*s', %d, %d)\n", cast(int)name.length, name.ptr, value, isAnonymous);
         this.name = name;
@@ -315,7 +315,7 @@ nothrow:
     /**********************************
      * ditto
      */
-    extern (D) static bool isValidIdentifier(const(char)[] str)
+    extern (D) static bool isValidIdentifier(const(char)[] str) @safe
     {
         if (str.length == 0 ||
             (str[0] >= '0' && str[0] <= '9')) // beware of isdigit() on signed chars
diff --git a/gcc/d/dmd/imphint.d b/gcc/d/dmd/imphint.d
index 913de9fa61c..9e9466a38eb 100644
--- a/gcc/d/dmd/imphint.d
+++ b/gcc/d/dmd/imphint.d
@@ -20,7 +20,7 @@ module dmd.imphint;
  * Not meant to be a comprehensive list of names in each module,
  * just the most common ones.
  */
-const(char)[] importHint(const(char)[] s)
+const(char)[] importHint(const(char)[] s) @safe
 {
     if (auto entry = s in hints)
         return *entry;
diff --git a/gcc/d/dmd/init.d b/gcc/d/dmd/init.d
index 6f20a3c7a45..e7cf9051034 100644
--- a/gcc/d/dmd/init.d
+++ b/gcc/d/dmd/init.d
@@ -51,7 +51,7 @@ extern (C++) class Initializer : ASTNode
     }
 
 
-    extern (D) this(const ref Loc loc, InitKind kind)
+    extern (D) this(const ref Loc loc, InitKind kind) @safe
     {
         this.loc = loc;
         this.kind = kind;
@@ -108,7 +108,7 @@ extern (C++) final class VoidInitializer : Initializer
 {
     Type type;      // type that this will initialize to
 
-    extern (D) this(const ref Loc loc)
+    extern (D) this(const ref Loc loc) @safe
     {
         super(loc, InitKind.void_);
     }
@@ -123,7 +123,7 @@ extern (C++) final class VoidInitializer : Initializer
  */
 extern (C++) final class ErrorInitializer : Initializer
 {
-    extern (D) this()
+    extern (D) this() @safe
     {
         super(Loc.initial, InitKind.error);
     }
@@ -206,7 +206,7 @@ extern (C++) final class ExpInitializer : Initializer
     bool expandTuples;
     Expression exp;
 
-    extern (D) this(const ref Loc loc, Expression exp)
+    extern (D) this(const ref Loc loc, Expression exp) @safe
     {
         super(loc, InitKind.exp);
         this.exp = exp;
@@ -226,8 +226,8 @@ struct Designator
     Expression exp;     /// [ constant-expression ]
     Identifier ident;   /// . identifier
 
-    this(Expression exp) { this.exp = exp; }
-    this(Identifier ident) { this.ident = ident; }
+    this(Expression exp) @safe { this.exp = exp; }
+    this(Identifier ident) @safe  { this.ident = ident; }
 }
 
 /*********************************************
@@ -377,7 +377,7 @@ mixin template VisitInitializer(Result)
  *      handler = string for the name of the visit handler
  * Returns: boilerplate code for a case
  */
-pure string visitCase(string handler)
+string visitCase(string handler) pure @safe
 {
     if (__ctfe)
     {
diff --git a/gcc/d/dmd/intrange.d b/gcc/d/dmd/intrange.d
index d67e0f5958d..442668f6337 100644
--- a/gcc/d/dmd/intrange.d
+++ b/gcc/d/dmd/intrange.d
@@ -18,7 +18,7 @@ import dmd.mtype;
 import dmd.expression;
 import dmd.globals;
 
-private uinteger_t copySign(uinteger_t x, bool sign)
+private uinteger_t copySign(uinteger_t x, bool sign) @safe
 {
     // return sign ? -x : x;
     return (x - cast(uinteger_t)sign) ^ -cast(uinteger_t)sign;
@@ -29,37 +29,37 @@ struct SignExtendedNumber
     uinteger_t value;
     bool negative;
 
-    static SignExtendedNumber fromInteger(uinteger_t value_)
+    static SignExtendedNumber fromInteger(uinteger_t value_) @safe
     {
         return SignExtendedNumber(value_, value_ >> 63);
     }
 
-    static SignExtendedNumber extreme(bool minimum)
+    static SignExtendedNumber extreme(bool minimum) @safe
     {
         return SignExtendedNumber(minimum - 1, minimum);
     }
 
-    static SignExtendedNumber max()
+    static SignExtendedNumber max() @safe
     {
         return SignExtendedNumber(ulong.max, false);
     }
 
-    static SignExtendedNumber min()
+    static SignExtendedNumber min() @safe
     {
         return SignExtendedNumber(0, true);
     }
 
-    bool isMinimum() const
+    bool isMinimum() const @safe
     {
         return negative && value == 0;
     }
 
-    bool opEquals(const ref SignExtendedNumber a) const
+    bool opEquals(const ref SignExtendedNumber a) const @safe
     {
         return value == a.value && negative == a.negative;
     }
 
-    int opCmp(const ref SignExtendedNumber a) const
+    int opCmp(const ref SignExtendedNumber a) const @safe
     {
         if (negative != a.negative)
         {
@@ -297,19 +297,19 @@ struct IntRange
 {
     SignExtendedNumber imin, imax;
 
-    this(IntRange another)
+    this(IntRange another) @safe
     {
         imin = another.imin;
         imax = another.imax;
     }
 
-    this(SignExtendedNumber a)
+    this(SignExtendedNumber a) @safe
     {
         imin = a;
         imax = a;
     }
 
-    this(SignExtendedNumber lower, SignExtendedNumber upper)
+    this(SignExtendedNumber lower, SignExtendedNumber upper) @safe
     {
         imin = lower;
         imax = upper;
@@ -358,12 +358,12 @@ struct IntRange
         return ab;
     }
 
-    static IntRange widest()
+    static IntRange widest() @safe
     {
         return IntRange(SignExtendedNumber.min(), SignExtendedNumber.max());
     }
 
-    IntRange castSigned(uinteger_t mask)
+    IntRange castSigned(uinteger_t mask) @safe
     {
         // .... 0x1e7f ] [0x1e80 .. 0x1f7f] [0x1f80 .. 0x7f] [0x80 .. 0x17f] [0x180 ....
         //
@@ -405,7 +405,7 @@ struct IntRange
         return this;
     }
 
-    IntRange castUnsigned(uinteger_t mask)
+    IntRange castUnsigned(uinteger_t mask) @safe
     {
         // .... 0x1eff ] [0x1f00 .. 0x1fff] [0 .. 0xff] [0x100 .. 0x1ff] [0x200 ....
         //
@@ -430,7 +430,7 @@ struct IntRange
         return this;
     }
 
-    IntRange castDchar()
+    IntRange castDchar() @safe
     {
         // special case for dchar. Casting to dchar means "I'll ignore all
         //  invalid characters."
@@ -464,18 +464,18 @@ struct IntRange
             return castUnsigned(type.sizemask());
     }
 
-    bool contains(IntRange a)
+    bool contains(IntRange a) @safe
     {
         return imin <= a.imin && imax >= a.imax;
     }
 
-    bool containsZero() const
+    bool containsZero() const @safe
     {
         return (imin.negative && !imax.negative)
             || (!imin.negative && imin.value == 0);
     }
 
-    IntRange absNeg() const
+    IntRange absNeg() const @safe
     {
         if (imax.negative)
             return this;
@@ -489,13 +489,13 @@ struct IntRange
         }
     }
 
-    IntRange unionWith(const ref IntRange other) const
+    IntRange unionWith(const ref IntRange other) const @safe
     {
         return IntRange(imin < other.imin ? imin : other.imin,
                         imax > other.imax ? imax : other.imax);
     }
 
-    void unionOrAssign(IntRange other, ref bool union_)
+    void unionOrAssign(IntRange other, ref bool union_) @safe
     {
         if (!union_ || imin > other.imin)
             imin = other.imin;
@@ -513,7 +513,7 @@ struct IntRange
         return this;
     }
 
-    void splitBySign(ref IntRange negRange, ref bool hasNegRange, ref IntRange nonNegRange, ref bool hasNonNegRange) const
+    void splitBySign(ref IntRange negRange, ref bool hasNegRange, ref IntRange nonNegRange, ref bool hasNonNegRange) const @safe
     {
         hasNegRange = imin.negative;
         if (hasNegRange)
@@ -785,7 +785,7 @@ struct IntRange
 private:
     // Credits to Timon Gehr maxOr, minOr, maxAnd, minAnd
     // https://github.com/tgehr/d-compiler/blob/master/vrange.d
-    static SignExtendedNumber maxOr(const IntRange lhs, const IntRange rhs)
+    static SignExtendedNumber maxOr(const IntRange lhs, const IntRange rhs) @safe
     {
         uinteger_t x = 0;
         auto sign = false;
@@ -856,14 +856,14 @@ private:
 
     // Credits to Timon Gehr maxOr, minOr, maxAnd, minAnd
     // https://github.com/tgehr/d-compiler/blob/master/vrange.d
-    static SignExtendedNumber minOr(const IntRange lhs, const IntRange rhs)
+    static SignExtendedNumber minOr(const IntRange lhs, const IntRange rhs) @safe
     {
         return ~maxAnd(~lhs, ~rhs);
     }
 
     // Credits to Timon Gehr maxOr, minOr, maxAnd, minAnd
     // https://github.com/tgehr/d-compiler/blob/master/vrange.d
-    static SignExtendedNumber maxAnd(const IntRange lhs, const IntRange rhs)
+    static SignExtendedNumber maxAnd(const IntRange lhs, const IntRange rhs) @safe
     {
         uinteger_t x = 0;
         bool sign = false;
@@ -905,7 +905,7 @@ private:
 
     // Credits to Timon Gehr maxOr, minOr, maxAnd, minAnd
     // https://github.com/tgehr/d-compiler/blob/master/vrange.d
-    static SignExtendedNumber minAnd(const IntRange lhs, const IntRange rhs)
+    static SignExtendedNumber minAnd(const IntRange lhs, const IntRange rhs) @safe
     {
         return ~maxOr(~lhs, ~rhs);
     }
diff --git a/gcc/d/dmd/json.d b/gcc/d/dmd/json.d
index dcf53b8f547..96899869d52 100644
--- a/gcc/d/dmd/json.d
+++ b/gcc/d/dmd/json.d
@@ -54,7 +54,7 @@ public:
     int indentLevel;
     const(char)[] filename;
 
-    extern (D) this(OutBuffer* buf) scope
+    extern (D) this(OutBuffer* buf) scope @safe
     {
         this.buf = buf;
     }
diff --git a/gcc/d/dmd/lambdacomp.d b/gcc/d/dmd/lambdacomp.d
index 885a27af905..ec070d8ec0b 100644
--- a/gcc/d/dmd/lambdacomp.d
+++ b/gcc/d/dmd/lambdacomp.d
@@ -395,7 +395,7 @@ public:
         if (s)
         {
             OutBuffer mangledName;
-            mangleToBuffer(s, &mangledName);
+            mangleToBuffer(s, mangledName);
             buf.writestring(mangledName[]);
             buf.writeByte('_');
         }
diff --git a/gcc/d/dmd/lexer.d b/gcc/d/dmd/lexer.d
index 9cce7c56723..c28fe5c2220 100644
--- a/gcc/d/dmd/lexer.d
+++ b/gcc/d/dmd/lexer.d
@@ -193,7 +193,7 @@ class Lexer
     /******************
      * Used for unittests for a mock Lexer
      */
-    this(ErrorSink errorSink) scope { assert(errorSink); this.eSink = errorSink; }
+    this(ErrorSink errorSink) scope @safe { assert(errorSink); this.eSink = errorSink; }
 
     /**************************************
      * Reset lexer to lex #define's
diff --git a/gcc/d/dmd/location.d b/gcc/d/dmd/location.d
index b2b366130ca..0f3b9a7aa44 100644
--- a/gcc/d/dmd/location.d
+++ b/gcc/d/dmd/location.d
@@ -64,7 +64,7 @@ nothrow:
         this.messageStyle = messageStyle;
     }
 
-    extern (D) this(const(char)* filename, uint linnum, uint charnum)
+    extern (D) this(const(char)* filename, uint linnum, uint charnum) @safe
     {
         this._linnum = linnum;
         this._charnum = cast(ushort) charnum;
@@ -108,7 +108,7 @@ nothrow:
      * Params:
      *   name = file name for location, null for no file name
      */
-    extern (C++) void filename(const(char)* name)
+    extern (C++) void filename(const(char)* name) @trusted
     {
         if (name)
         {
@@ -205,7 +205,7 @@ nothrow:
      * Returns:
      *   true if Loc has been set to other than the default initialization
      */
-    bool isValid() const pure
+    bool isValid() const pure @safe
     {
         return fileIndex != 0;
     }
diff --git a/gcc/d/dmd/mangle.h b/gcc/d/dmd/mangle.h
index 37953c2ca4a..aa246988f2e 100644
--- a/gcc/d/dmd/mangle.h
+++ b/gcc/d/dmd/mangle.h
@@ -28,7 +28,7 @@ const char *cppTypeInfoMangleMSVC(Dsymbol *s);
 
 // In dmangle.d
 const char *mangleExact(FuncDeclaration *fd);
-void mangleToBuffer(Type *s, OutBuffer *buf);
-void mangleToBuffer(Expression *s, OutBuffer *buf);
-void mangleToBuffer(Dsymbol *s, OutBuffer *buf);
-void mangleToBuffer(TemplateInstance *s, OutBuffer *buf);
+void mangleToBuffer(Type *s, OutBuffer& buf);
+void mangleToBuffer(Expression *s, OutBuffer& buf);
+void mangleToBuffer(Dsymbol *s, OutBuffer& buf);
+void mangleToBuffer(TemplateInstance *s, OutBuffer& buf);
diff --git a/gcc/d/dmd/mtype.d b/gcc/d/dmd/mtype.d
index 7ecd4023ee1..9d83db13b67 100644
--- a/gcc/d/dmd/mtype.d
+++ b/gcc/d/dmd/mtype.d
@@ -157,7 +157,7 @@ MOD MODmerge(MOD mod1, MOD mod2) pure nothrow @nogc @safe
 /*********************************
  * Store modifier name into buf.
  */
-void MODtoBuffer(OutBuffer* buf, MOD mod) nothrow
+void MODtoBuffer(OutBuffer* buf, MOD mod) nothrow @safe
 {
     buf.writestring(MODtoString(mod));
 }
@@ -174,7 +174,7 @@ const(char)* MODtoChars(MOD mod) nothrow pure
 }
 
 /// Ditto
-string MODtoString(MOD mod) nothrow pure
+string MODtoString(MOD mod) nothrow pure @safe
 {
     final switch (mod)
     {
@@ -457,7 +457,7 @@ extern (C++) abstract class Type : ASTNode
             return sizeTy;
         }();
 
-    final extern (D) this(TY ty) scope
+    final extern (D) this(TY ty) scope @safe
     {
         this.ty = ty;
     }
@@ -2434,7 +2434,7 @@ extern (C++) abstract class Type : ASTNode
         // _init_10TypeInfo_%s
         OutBuffer buf;
         buf.reserve(32);
-        mangleToBuffer(this, &buf);
+        mangleToBuffer(this, buf);
 
         const slice = buf[];
 
@@ -2780,7 +2780,7 @@ extern (C++) abstract class Type : ASTNode
  */
 extern (C++) final class TypeError : Type
 {
-    extern (D) this()
+    extern (D) this() @safe
     {
         super(Terror);
     }
@@ -2818,7 +2818,7 @@ extern (C++) abstract class TypeNext : Type
 {
     Type next;
 
-    final extern (D) this(TY ty, Type next)
+    final extern (D) this(TY ty, Type next) @safe
     {
         super(ty);
         this.next = next;
@@ -3517,13 +3517,13 @@ extern (C++) final class TypeVector : Type
 {
     Type basetype;
 
-    extern (D) this(Type basetype)
+    extern (D) this(Type basetype) @safe
     {
         super(Tvector);
         this.basetype = basetype;
     }
 
-    static TypeVector create(Type basetype)
+    static TypeVector create(Type basetype) @safe
     {
         return new TypeVector(basetype);
     }
@@ -3632,7 +3632,7 @@ extern (C++) final class TypeVector : Type
  */
 extern (C++) abstract class TypeArray : TypeNext
 {
-    final extern (D) this(TY ty, Type next)
+    final extern (D) this(TY ty, Type next) @safe
     {
         super(ty, next);
     }
@@ -3650,7 +3650,7 @@ extern (C++) final class TypeSArray : TypeArray
 {
     Expression dim;
 
-    extern (D) this(Type t, Expression dim)
+    extern (D) this(Type t, Expression dim) @safe
     {
         super(Tsarray, t);
         //printf("TypeSArray(%s)\n", dim.toChars());
@@ -3874,7 +3874,7 @@ extern (C++) final class TypeSArray : TypeArray
  */
 extern (C++) final class TypeDArray : TypeArray
 {
-    extern (D) this(Type t)
+    extern (D) this(Type t) @safe
     {
         super(Tarray, t);
         //printf("TypeDArray(t = %p)\n", t);
@@ -3972,13 +3972,13 @@ extern (C++) final class TypeAArray : TypeArray
     Type index;     // key type
     Loc loc;
 
-    extern (D) this(Type t, Type index)
+    extern (D) this(Type t, Type index) @safe
     {
         super(Taarray, t);
         this.index = index;
     }
 
-    static TypeAArray create(Type t, Type index)
+    static TypeAArray create(Type t, Type index) @safe
     {
         return new TypeAArray(t, index);
     }
@@ -4066,12 +4066,12 @@ extern (C++) final class TypeAArray : TypeArray
  */
 extern (C++) final class TypePointer : TypeNext
 {
-    extern (D) this(Type t)
+    extern (D) this(Type t) @safe
     {
         super(Tpointer, t);
     }
 
-    static TypePointer create(Type t)
+    static TypePointer create(Type t) @safe
     {
         return new TypePointer(t);
     }
@@ -4173,7 +4173,7 @@ extern (C++) final class TypePointer : TypeNext
  */
 extern (C++) final class TypeReference : TypeNext
 {
-    extern (D) this(Type t)
+    extern (D) this(Type t) @safe
     {
         super(Treference, t);
         // BUG: what about references to static arrays?
@@ -4263,7 +4263,7 @@ extern (C++) final class TypeFunction : TypeNext
     byte inuse;
     Expressions* fargs;         // function arguments
 
-    extern (D) this(ParameterList pl, Type treturn, LINK linkage, StorageClass stc = 0)
+    extern (D) this(ParameterList pl, Type treturn, LINK linkage, StorageClass stc = 0) @safe
     {
         super(Tfunction, treturn);
         //if (!treturn) *(char*)0=0;
@@ -4305,7 +4305,7 @@ extern (C++) final class TypeFunction : TypeNext
             this.trust = TRUST.trusted;
     }
 
-    static TypeFunction create(Parameters* parameters, Type treturn, ubyte varargs, LINK linkage, StorageClass stc = 0)
+    static TypeFunction create(Parameters* parameters, Type treturn, ubyte varargs, LINK linkage, StorageClass stc = 0) @safe
     {
         return new TypeFunction(ParameterList(parameters, cast(VarArg)varargs), treturn, linkage, stc);
     }
@@ -5013,13 +5013,13 @@ extern (C++) final class TypeDelegate : TypeNext
 {
     // .next is a TypeFunction
 
-    extern (D) this(TypeFunction t)
+    extern (D) this(TypeFunction t) @safe
     {
         super(Tfunction, t);
         ty = Tdelegate;
     }
 
-    static TypeDelegate create(TypeFunction t)
+    static TypeDelegate create(TypeFunction t) @safe
     {
         return new TypeDelegate(t);
     }
@@ -5114,7 +5114,7 @@ extern (C++) final class TypeTraits : Type
     /// Cached type/symbol after semantic analysis.
     RootObject obj;
 
-    final extern (D) this(const ref Loc loc, TraitsExp exp)
+    final extern (D) this(const ref Loc loc, TraitsExp exp) @safe
     {
         super(Ttraits);
         this.loc = loc;
@@ -5170,7 +5170,7 @@ extern (C++) final class TypeMixin : Type
     Expressions* exps;
     RootObject obj; // cached result of semantic analysis.
 
-    extern (D) this(const ref Loc loc, Expressions* exps)
+    extern (D) this(const ref Loc loc, Expressions* exps) @safe
     {
         super(Tmixin);
         this.loc = loc;
@@ -5494,13 +5494,13 @@ extern (C++) final class TypeStruct : Type
     AliasThisRec att = AliasThisRec.fwdref;
     bool inuse = false; // struct currently subject of recursive method call
 
-    extern (D) this(StructDeclaration sym)
+    extern (D) this(StructDeclaration sym) @safe
     {
         super(Tstruct);
         this.sym = sym;
     }
 
-    static TypeStruct create(StructDeclaration sym)
+    static TypeStruct create(StructDeclaration sym) @safe
     {
         return new TypeStruct(sym);
     }
@@ -5830,7 +5830,7 @@ extern (C++) final class TypeEnum : Type
 {
     EnumDeclaration sym;
 
-    extern (D) this(EnumDeclaration sym)
+    extern (D) this(EnumDeclaration sym) @safe
     {
         super(Tenum);
         this.sym = sym;
@@ -6008,7 +6008,7 @@ extern (C++) final class TypeClass : Type
     AliasThisRec att = AliasThisRec.fwdref;
     CPPMANGLE cppmangle = CPPMANGLE.def;
 
-    extern (D) this(ClassDeclaration sym)
+    extern (D) this(ClassDeclaration sym) @safe
     {
         super(Tclass);
         this.sym = sym;
@@ -6184,7 +6184,7 @@ extern (C++) final class TypeTuple : Type
 
     Parameters* arguments;  // types making up the tuple
 
-    extern (D) this(Parameters* arguments)
+    extern (D) this(Parameters* arguments) @safe
     {
         super(Ttuple);
         //printf("TypeTuple(this = %p)\n", this);
@@ -6226,7 +6226,7 @@ extern (C++) final class TypeTuple : Type
         //printf("TypeTuple() %p, %s\n", this, toChars());
     }
 
-    static TypeTuple create(Parameters* arguments)
+    static TypeTuple create(Parameters* arguments) @safe
     {
         return new TypeTuple(arguments);
     }
@@ -6234,7 +6234,7 @@ extern (C++) final class TypeTuple : Type
     /*******************************************
      * Type tuple with 0, 1 or 2 types in it.
      */
-    extern (D) this()
+    extern (D) this() @safe
     {
         super(Ttuple);
         arguments = new Parameters();
@@ -6255,7 +6255,7 @@ extern (C++) final class TypeTuple : Type
         arguments.push(new Parameter(0, t2, null, null, null));
     }
 
-    static TypeTuple create()
+    static TypeTuple create() @safe
     {
         return new TypeTuple();
     }
@@ -6343,7 +6343,7 @@ extern (C++) final class TypeSlice : TypeNext
     Expression lwr;
     Expression upr;
 
-    extern (D) this(Type next, Expression lwr, Expression upr)
+    extern (D) this(Type next, Expression lwr, Expression upr) @safe
     {
         super(Tslice, next);
         //printf("TypeSlice[%s .. %s]\n", lwr.toChars(), upr.toChars());
@@ -6373,7 +6373,7 @@ extern (C++) final class TypeSlice : TypeNext
  */
 extern (C++) final class TypeNull : Type
 {
-    extern (D) this()
+    extern (D) this() @safe
     {
         //printf("TypeNull %p\n", this);
         super(Tnull);
@@ -6438,7 +6438,7 @@ extern (C++) final class TypeNull : Type
  */
 extern (C++) final class TypeNoreturn : Type
 {
-    extern (D) this()
+    extern (D) this() @safe
     {
         //printf("TypeNoreturn %p\n", this);
         super(Tnoreturn);
@@ -6520,7 +6520,7 @@ extern (C++) final class TypeTag : Type
                             ///   struct S { int a; } s1, *s2;
     MOD mod;                /// modifiers to apply after type is resolved (only MODFlags.const_ at the moment)
 
-    extern (D) this(const ref Loc loc, TOK tok, Identifier id, structalign_t packalign, Type base, Dsymbols* members)
+    extern (D) this(const ref Loc loc, TOK tok, Identifier id, structalign_t packalign, Type base, Dsymbols* members) @safe
     {
         //printf("TypeTag ctor %s %p\n", id ? id.toChars() : "null".ptr, this);
         super(Ttag);
@@ -6564,7 +6564,7 @@ extern (C++) struct ParameterList
     VarArg varargs = VarArg.none;
     bool hasIdentifierList;             // true if C identifier-list style
 
-    this(Parameters* parameters, VarArg varargs = VarArg.none, StorageClass stc = 0)
+    this(Parameters* parameters, VarArg varargs = VarArg.none, StorageClass stc = 0) @safe
     {
         this.parameters = parameters;
         this.varargs = varargs;
@@ -6667,7 +6667,7 @@ extern (C++) final class Parameter : ASTNode
     Expression defaultArg;
     UserAttributeDeclaration userAttribDecl; // user defined attributes
 
-    extern (D) this(StorageClass storageClass, Type type, Identifier ident, Expression defaultArg, UserAttributeDeclaration userAttribDecl)
+    extern (D) this(StorageClass storageClass, Type type, Identifier ident, Expression defaultArg, UserAttributeDeclaration userAttribDecl) @safe
     {
         this.type = type;
         this.ident = ident;
@@ -6676,7 +6676,7 @@ extern (C++) final class Parameter : ASTNode
         this.userAttribDecl = userAttribDecl;
     }
 
-    static Parameter create(StorageClass storageClass, Type type, Identifier ident, Expression defaultArg, UserAttributeDeclaration userAttribDecl)
+    static Parameter create(StorageClass storageClass, Type type, Identifier ident, Expression defaultArg, UserAttributeDeclaration userAttribDecl) @safe
     {
         return new Parameter(storageClass, type, ident, defaultArg, userAttribDecl);
     }
@@ -7646,7 +7646,7 @@ mixin template VisitType(Result)
  *      handler = string for the name of the visit handler
  * Returns: boilerplate code for a case
  */
-pure string visitTYCase(string handler)
+pure string visitTYCase(string handler) @safe
 {
     if (__ctfe)
     {
diff --git a/gcc/d/dmd/mtype.h b/gcc/d/dmd/mtype.h
index fbfd766fa94..457b91f1cee 100644
--- a/gcc/d/dmd/mtype.h
+++ b/gcc/d/dmd/mtype.h
@@ -123,8 +123,9 @@ enum VarArgValues
 {
     VARARGnone     = 0,  /// fixed number of arguments
     VARARGvariadic = 1,  /// T t, ...)  can be C-style (core.stdc.stdarg) or D-style (core.vararg)
-    VARARGtypesafe = 2   /// T t ...) typesafe https://dlang.org/spec/function.html#typesafe_variadic_functions
+    VARARGtypesafe = 2,  /// T t ...) typesafe https://dlang.org/spec/function.html#typesafe_variadic_functions
                          ///   or https://dlang.org/spec/function.html#typesafe_variadic_functions
+    VARARGKRvariadic = 3 /// K+R C style variadics (no function prototype)
 };
 typedef unsigned char VarArg;
 
diff --git a/gcc/d/dmd/mustuse.d b/gcc/d/dmd/mustuse.d
index 11cc3b8d6d8..844f719e0b8 100644
--- a/gcc/d/dmd/mustuse.d
+++ b/gcc/d/dmd/mustuse.d
@@ -18,11 +18,11 @@ import dmd.identifier;
 import dmd.location;
 
 // Used in isIncrementOrDecrement
-private static const StringExp plusPlus, minusMinus;
+private const StringExp plusPlus, minusMinus;
 
 // Loc.initial cannot be used in static initializers, so
 // these need a static constructor.
-static this()
+shared static this()
 {
     plusPlus = new StringExp(Loc.initial, "++");
     minusMinus = new StringExp(Loc.initial, "--");
diff --git a/gcc/d/dmd/nogc.d b/gcc/d/dmd/nogc.d
index d7a28209b3e..01a6832a97b 100644
--- a/gcc/d/dmd/nogc.d
+++ b/gcc/d/dmd/nogc.d
@@ -19,6 +19,7 @@ import dmd.aggregate;
 import dmd.astenums;
 import dmd.declaration;
 import dmd.dscope;
+import dmd.dtemplate : isDsymbol;
 import dmd.errors;
 import dmd.expression;
 import dmd.func;
@@ -40,7 +41,7 @@ public:
     bool checkOnly;     // don't print errors
     bool err;
 
-    extern (D) this(FuncDeclaration f) scope
+    extern (D) this(FuncDeclaration f) scope @safe
     {
         this.f = f;
     }
@@ -263,6 +264,7 @@ private FuncDeclaration stripHookTraceImpl(FuncDeclaration fd)
     // Get the Hook from the second template parameter
     auto templateInstance = fd.parent.isTemplateInstance;
     RootObject hook = (*templateInstance.tiargs)[1];
-    assert(hook.dyncast() == DYNCAST.dsymbol, "Expected _d_HookTraceImpl's second template parameter to be an alias to the hook!");
-    return (cast(Dsymbol)hook).isFuncDeclaration;
+    Dsymbol s = hook.isDsymbol();
+    assert(s, "Expected _d_HookTraceImpl's second template parameter to be an alias to the hook!");
+    return s.isFuncDeclaration;
 }
diff --git a/gcc/d/dmd/ob.d b/gcc/d/dmd/ob.d
index 56243a0e035..4774d1f5243 100644
--- a/gcc/d/dmd/ob.d
+++ b/gcc/d/dmd/ob.d
@@ -145,7 +145,7 @@ enum ObType : ubyte
     fend,
 }
 
-string toString(ObType obtype)
+string toString(ObType obtype) @safe
 {
     return obtype == ObType.goto_     ? "goto  "  :
            obtype == ObType.return_   ? "ret   "  :
@@ -202,7 +202,7 @@ const(char)* toChars(PtrState state)
     return toString(state).ptr;
 }
 
-string toString(PtrState state)
+string toString(PtrState state) @safe
 {
     return ["Initial", "Undefined", "Owner", "Borrowed", "Readonly"][state];
 }
@@ -1012,7 +1012,7 @@ void insertFinallyBlockGotos(ref ObNodes obnodes)
  * Set the `index` field of each ObNode
  * to its index in the `obnodes[]` array.
  */
-void numberNodes(ref ObNodes obnodes)
+void numberNodes(ref ObNodes obnodes) @safe
 {
     //printf("numberNodes()\n");
     foreach (i, ob; obnodes)
diff --git a/gcc/d/dmd/objc.d b/gcc/d/dmd/objc.d
index c493323e238..623a362907e 100644
--- a/gcc/d/dmd/objc.d
+++ b/gcc/d/dmd/objc.d
@@ -58,7 +58,7 @@ struct ObjcSelector
         stringtable._init();
     }
 
-    extern (D) this(const(char)* sv, size_t len, size_t pcount)
+    extern (D) this(const(char)* sv, size_t len, size_t pcount) @safe
     {
         stringvalue = sv;
         stringlen = len;
@@ -119,7 +119,7 @@ struct ObjcSelector
             buf.writeByte('_');
             foreach (i, fparam; ftype.parameterList)
             {
-                mangleToBuffer(fparam.type, &buf);
+                mangleToBuffer(fparam.type, buf);
                 buf.writeByte(':');
             }
         }
@@ -167,12 +167,12 @@ extern (C++) struct ObjcClassDeclaration
     /// List of non-inherited methods.
     FuncDeclaration[] methodList;
 
-    extern (D) this(ClassDeclaration classDeclaration)
+    extern (D) this(ClassDeclaration classDeclaration) @safe
     {
         this.classDeclaration = classDeclaration;
     }
 
-    bool isRootClass() const
+    bool isRootClass() const @safe
     {
         return classDeclaration.classKind == ClassKind.objc &&
             !metaclass &&
diff --git a/gcc/d/dmd/opover.d b/gcc/d/dmd/opover.d
index 8b42a91f0af..457e8b6479c 100644
--- a/gcc/d/dmd/opover.d
+++ b/gcc/d/dmd/opover.d
@@ -43,7 +43,7 @@ import dmd.visitor;
  * Determine if operands of binary op can be reversed
  * to fit operator overload.
  */
-bool isCommutative(EXP op)
+bool isCommutative(EXP op) @safe
 {
     switch (op)
     {
@@ -1840,7 +1840,7 @@ private bool matchParamsToOpApply(TypeFunction tf, Parameters* parameters, bool
  * Returns:
  *      reverse of op
  */
-private EXP reverseRelation(EXP op) pure
+private EXP reverseRelation(EXP op) pure @safe
 {
     switch (op)
     {
diff --git a/gcc/d/dmd/parse.d b/gcc/d/dmd/parse.d
index d15e448150f..13bba4fb284 100644
--- a/gcc/d/dmd/parse.d
+++ b/gcc/d/dmd/parse.d
@@ -1222,7 +1222,10 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
                       (orig & STC.scope_) ? "scope".ptr : "ref".ptr);
             }
             else if (added & STC.ref_)
-                deprecation("using `in ref` is deprecated, use `-preview=in` and `in` instead");
+            {
+                // accept for legacy compatibility
+                //deprecation("using `in ref` is deprecated, use `-preview=in` and `in` instead");
+            }
             else
                 error("attribute `scope` cannot be applied with `in`, use `-preview=in` instead");
             return orig;
@@ -1240,7 +1243,10 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
                       stc_str, stc_str);
             }
             else if (orig & STC.ref_)
-                deprecation("using `ref in` is deprecated, use `-preview=in` and `in` instead");
+            {
+                // accept for legacy compatibility
+                //deprecation("using `in ref` is deprecated, use `-preview=in` and `in` instead");
+            }
             else
                 error("attribute `in` cannot be added after `scope`: remove `scope` and use `-preview=in`");
             return orig;
@@ -3042,7 +3048,6 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
         else if (token.value == TOK.leftCurly)
         {
             bool isAnonymousEnum = !id;
-            TOK prevTOK;
 
             //printf("enum definition\n");
             e.members = new AST.Dsymbols();
@@ -3065,9 +3070,8 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
                 StorageClass stc;
                 AST.Expression deprecationMessage;
                 enum attributeErrorMessage = "`%s` is not a valid attribute for enum members";
-                while(token.value != TOK.rightCurly
-                    && token.value != TOK.comma
-                    && token.value != TOK.assign)
+            Lattrs:
+                while (1)
                 {
                     switch (token.value)
                     {
@@ -3082,7 +3086,6 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
                                     AST.stcToBuffer(&buf, _stc);
                                     error(attributeErrorMessage, buf.peekChars());
                                 }
-                                prevTOK = token.value;
                                 nextToken();
                             }
                             break;
@@ -3090,94 +3093,86 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
                             stc |= STC.deprecated_;
                             if (!parseDeprecatedAttribute(deprecationMessage))
                             {
-                                prevTOK = token.value;
-                                nextToken();
-                            }
-                            break;
-                        case TOK.identifier:
-                            const tv = peekNext();
-                            if (tv == TOK.assign || tv == TOK.comma || tv == TOK.rightCurly)
-                            {
-                                ident = token.ident;
-                                type = null;
-                                prevTOK = token.value;
                                 nextToken();
                             }
-                            else
-                            {
-                                if (isAnonymousEnum)
-                                    goto default; // maybe `Type identifier`
-
-                                prevTOK = token.value;
-                                nextToken();
-                                error("expected `,` or `=` after identifier, not `%s`", token.toChars());
-                            }
                             break;
                         default:
-                            if (isAnonymousEnum)
-                            {
-                                if (type)
-                                {
-                                    error("expected identifier after type, not `%s`", token.toChars());
-                                    type = null;
-                                    break;
-                                }
-                                type = parseType(&ident, null);
-                                if (type == AST.Type.terror)
-                                {
-                                    type = null;
-                                    prevTOK = token.value;
-                                    nextToken();
-                                }
-                                else
-                                {
-                                    prevTOK = TOK.identifier;
-                                    const tv = token.value;
-                                    if (ident && tv != TOK.assign && tv != TOK.comma && tv != TOK.rightCurly)
-                                    {
-                                        error("expected `,` or `=` after identifier, not `%s`", token.toChars());
-                                    }
-                                }
-                            }
-                            else
-                            {
-                                error(attributeErrorMessage, token.toChars());
-                                prevTOK = token.value;
-                                nextToken();
-                            }
-                            break;
+                            break Lattrs;
                     }
-                    if (token.value == TOK.comma)
+                }
+                if (token.value == TOK.identifier)
+                {
+                    const tv = peekNext();
+                    if (tv == TOK.assign || tv == TOK.comma || tv == TOK.rightCurly)
                     {
-                        prevTOK = token.value;
+                        ident = token.ident;
+                        type = null;
+                        nextToken();
                     }
-                }
+                    else
+                    {
+                        if (isAnonymousEnum)
+                            goto Ltype;
 
-                if (type && type != AST.Type.terror)
-                {
-                    if (!ident)
-                        error("no identifier for declarator `%s`", type.toChars());
-                    if (!isAnonymousEnum)
-                        error("type only allowed if anonymous enum and no enum type");
+                        nextToken();
+                        error("expected `,` or `=` after identifier, not `%s`", token.toChars());
+                    }
                 }
-                AST.Expression value;
-                if (token.value == TOK.assign)
+                else
                 {
-                    if (prevTOK == TOK.identifier)
+                    if (isAnonymousEnum)
                     {
-                        nextToken();
-                        value = parseAssignExp();
+                    Ltype:
+                        // Type identifier
+                        type = parseType(&ident, null);
+                        if (type == AST.Type.terror)
+                        {
+                            type = null;
+                            nextToken();
+                        }
+                        else if (!ident)
+                        {
+                            error("no identifier for declarator `%s`", type.toChars());
+                            type = null;
+                        }
+                        else
+                        {
+                            const tv = token.value;
+                            if (tv != TOK.assign && tv != TOK.comma && tv != TOK.rightCurly)
+                            {
+                                error("expected `,` or `=` after identifier, not `%s`", token.toChars());
+                                nextToken();
+                            }
+                        }
                     }
                     else
                     {
-                        error("assignment must be preceded by an identifier");
-                        nextToken();
+                        Token* t = &token;
+                        if (isBasicType(&t))
+                        {
+                            error("named enum cannot declare member with type", (*t).toChars());
+                            nextToken();
+                        }
+                        else
+                            check(TOK.identifier);
+
+                        // avoid extra error messages
+                        const tv = token.value;
+                        if (tv != TOK.assign && tv != TOK.comma && tv != TOK.rightCurly && tv != TOK.endOfFile)
+                            continue;
                     }
                 }
+
+                AST.Expression value;
+                if (token.value == TOK.assign)
+                {
+                    nextToken();
+                    value = parseAssignExp();
+                }
                 else
                 {
                     value = null;
-                    if (type && type != AST.Type.terror && isAnonymousEnum)
+                    if (type && isAnonymousEnum)
                         error("initializer required after `%s` when type is specified", ident.toChars());
                 }
 
@@ -3197,10 +3192,7 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
                     em.userAttribDecl = uad;
                 }
 
-                if (token.value == TOK.rightCurly)
-                {
-                }
-                else
+                if (token.value != TOK.rightCurly)
                 {
                     addComment(em, comment);
                     comment = null;
@@ -3218,8 +3210,10 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
             nextToken();
         }
         else
-            error("enum declaration is invalid");
-
+        {
+            nextToken();
+            error("expected `{`, not `%s` for enum declaration", token.toChars());
+        }
         //printf("-parseEnum() %s\n", e.toChars());
         return e;
     }
@@ -4611,6 +4605,13 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
                  */
                 if (tpl)
                 {
+                    // @@@DEPRECATED_2.114@@@
+                    // Both deprecated in 2.104, change to error
+                    if (storage_class & STC.override_)
+                        deprecation(loc, "a function template is not virtual so cannot be marked `override`");
+                    else if (storage_class & STC.abstract_)
+                        deprecation(loc, "a function template is not virtual so cannot be marked `abstract`");
+
                     // Wrap a template around the function declaration
                     auto decldefs = new AST.Dsymbols();
                     decldefs.push(s);
@@ -5622,60 +5623,61 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
         AST.Parameter param = null;
         StorageClass storageClass = 0;
         StorageClass stc = 0;
-LagainStc:
-        if (stc)
-        {
-            storageClass = appendStorageClass(storageClass, stc);
-            nextToken();
-        }
-        switch (token.value)
+    Lwhile:
+        while (1)
         {
-        case TOK.ref_:
-            stc = STC.ref_;
-            goto LagainStc;
+            switch (token.value)
+            {
+            // parse ref for better error
+            case TOK.ref_:
+                stc = STC.ref_;
+                break;
 
-        case TOK.scope_:
-            stc = STC.scope_;
-            goto LagainStc;
+            case TOK.scope_:
+                stc = STC.scope_;
+                break;
 
-        case TOK.auto_:
-            stc = STC.auto_;
-            goto LagainStc;
+            case TOK.auto_:
+                stc = STC.auto_;
+                break;
 
-        case TOK.const_:
-            if (peekNext() != TOK.leftParenthesis)
-            {
-                stc = STC.const_;
-                goto LagainStc;
-            }
-            break;
+            case TOK.const_:
+                if (peekNext() != TOK.leftParenthesis)
+                {
+                    stc = STC.const_;
+                    break;
+                }
+                goto default;
 
-        case TOK.immutable_:
-            if (peekNext() != TOK.leftParenthesis)
-            {
-                stc = STC.immutable_;
-                goto LagainStc;
-            }
-            break;
+            case TOK.immutable_:
+                if (peekNext() != TOK.leftParenthesis)
+                {
+                    stc = STC.immutable_;
+                    break;
+                }
+                goto default;
 
-        case TOK.shared_:
-            if (peekNext() != TOK.leftParenthesis)
-            {
-                stc = STC.shared_;
-                goto LagainStc;
-            }
-            break;
+            case TOK.shared_:
+                if (peekNext() != TOK.leftParenthesis)
+                {
+                    stc = STC.shared_;
+                    break;
+                }
+                goto default;
 
-        case TOK.inout_:
-            if (peekNext() != TOK.leftParenthesis)
-            {
-                stc = STC.wild;
-                goto LagainStc;
-            }
-            break;
+            case TOK.inout_:
+                if (peekNext() != TOK.leftParenthesis)
+                {
+                    stc = STC.wild;
+                    break;
+                }
+                goto default;
 
-        default:
-            break;
+            default:
+                break Lwhile;
+            }
+            storageClass = appendStorageClass(storageClass, stc);
+            nextToken();
         }
         auto n = peek(&token);
         if (storageClass != 0 && token.value == TOK.identifier && n.value == TOK.assign)
@@ -8709,7 +8711,8 @@ LagainStc:
                     nextToken();
                     if (token.value != TOK.identifier)
                     {
-                        error("identifier expected following `(type)`.");
+                        error("identifier expected following `%s.`, not `%s`",
+                            t.toChars(), token.toChars());
                         return AST.ErrorExp.get();
                     }
                     e = new AST.DotIdExp(loc, new AST.TypeExp(loc, t), token.ident);
@@ -8721,7 +8724,8 @@ LagainStc:
                     e = new AST.TypeExp(loc, t);
                     if (token.value != TOK.leftParenthesis)
                     {
-                        error("`(arguments)` expected following `%s`", t.toChars());
+                        error("`(arguments)` expected following `%s`, not `%s`",
+                            t.toChars(), token.toChars());
                         return e;
                     }
                     e = new AST.CallExp(loc, e, parseArguments());
diff --git a/gcc/d/dmd/postordervisitor.d b/gcc/d/dmd/postordervisitor.d
index a0c71150c0f..70bd1300feb 100644
--- a/gcc/d/dmd/postordervisitor.d
+++ b/gcc/d/dmd/postordervisitor.d
@@ -40,7 +40,7 @@ private extern (C++) final class PostorderExpressionVisitor : StoppableVisitor
 public:
     StoppableVisitor v;
 
-    extern (D) this(StoppableVisitor v) scope
+    extern (D) this(StoppableVisitor v) scope @safe
     {
         this.v = v;
     }
diff --git a/gcc/d/dmd/printast.d b/gcc/d/dmd/printast.d
index 8c0109524f7..e43ffad2570 100644
--- a/gcc/d/dmd/printast.d
+++ b/gcc/d/dmd/printast.d
@@ -39,7 +39,7 @@ extern (C++) final class PrintASTVisitor : Visitor
 
     int indent;
 
-    extern (D) this(int indent) scope
+    extern (D) this(int indent) scope @safe
     {
         this.indent = indent;
     }
diff --git a/gcc/d/dmd/root/complex.d b/gcc/d/dmd/root/complex.d
index fc93bd7d404..57d1e340eff 100644
--- a/gcc/d/dmd/root/complex.d
+++ b/gcc/d/dmd/root/complex.d
@@ -29,7 +29,7 @@ extern (C++) struct complex_t
         this(re, CTFloat.zero);
     }
 
-    this(real_t re, real_t im)
+    this(real_t re, real_t im) @safe
     {
         this.re = re;
         this.im = im;
@@ -99,18 +99,18 @@ extern (C++) struct complex_t
         return re || im;
     }
 
-    int opEquals(complex_t y) const
+    int opEquals(complex_t y) const @safe
     {
         return re == y.re && im == y.im;
     }
 }
 
-extern (C++) real_t creall(complex_t x)
+extern (C++) real_t creall(complex_t x) @safe
 {
     return x.re;
 }
 
-extern (C++) real_t cimagl(complex_t x)
+extern (C++) real_t cimagl(complex_t x) @safe
 {
     return x.im;
 }
diff --git a/gcc/d/dmd/root/filename.d b/gcc/d/dmd/root/filename.d
index 387361568e0..987c79391cc 100644
--- a/gcc/d/dmd/root/filename.d
+++ b/gcc/d/dmd/root/filename.d
@@ -41,9 +41,6 @@ version (Windows)
     extern (Windows) DWORD GetFullPathNameW(LPCWSTR, DWORD, LPWSTR, LPWSTR*) nothrow @nogc;
     extern (Windows) void SetLastError(DWORD) nothrow @nogc;
     extern (C) char* getcwd(char* buffer, size_t maxlen) nothrow;
-
-    // assume filenames encoded in system default Windows ANSI code page
-    private enum CodePage = CP_ACP;
 }
 
 version (CRuntime_Glibc)
@@ -127,7 +124,7 @@ nothrow:
     }
 
     /// Ditto
-    extern (D) static bool absolute(const(char)[] name) pure @nogc
+    extern (D) static bool absolute(const(char)[] name) pure @nogc @safe
     {
         if (!name.length)
             return false;
@@ -280,7 +277,7 @@ nothrow:
     }
 
     /// Ditto
-    extern (D) static const(char)[] name(const(char)[] str) pure @nogc
+    extern (D) static const(char)[] name(const(char)[] str) pure @nogc @safe
     {
         foreach_reverse (idx, char e; str)
         {
@@ -1147,6 +1144,8 @@ version(Windows)
      */
     char[] toNarrowStringz(const(wchar)[] wide, char[] buffer = null) nothrow
     {
+        import dmd.common.file : CodePage;
+
         if (wide is null)
             return null;
 
diff --git a/gcc/d/dmd/root/longdouble.d b/gcc/d/dmd/root/longdouble.d
index 5bbed22357c..8702365ebea 100644
--- a/gcc/d/dmd/root/longdouble.d
+++ b/gcc/d/dmd/root/longdouble.d
@@ -25,12 +25,15 @@ import core.stdc.stdint;
 extern(C++):
 nothrow:
 @nogc:
+pure:
+@trusted:
 
 // Type used by the front-end for compile-time reals
 struct longdouble
 {
 nothrow:
 @nogc:
+pure:
     extern (D) this(T)(T r)
     {
         this.set(cast(SetType!T)r);
diff --git a/gcc/d/dmd/root/rmem.d b/gcc/d/dmd/root/rmem.d
index 9b1d9fba524..cff5c4cf7ec 100644
--- a/gcc/d/dmd/root/rmem.d
+++ b/gcc/d/dmd/root/rmem.d
@@ -110,7 +110,7 @@ extern (C++) struct Mem
      * Returns:
      *  p if not null
      */
-    static void* check(void* p) pure nothrow @nogc
+    static void* check(void* p) pure nothrow @nogc @safe
     {
         return p ? p : error();
     }
diff --git a/gcc/d/dmd/root/utf.d b/gcc/d/dmd/root/utf.d
index c9781a46bc6..d7ba17f8a0b 100644
--- a/gcc/d/dmd/root/utf.d
+++ b/gcc/d/dmd/root/utf.d
@@ -11,7 +11,7 @@
 
 module dmd.root.utf;
 
-nothrow pure @nogc:
+@nogc nothrow pure @safe:
 
 /// The Unicode code space is the range of code points [0x000000,0x10FFFF]
 /// except the UTF-16 surrogate pairs in the range [0xD800,0xDFFF]
@@ -337,7 +337,7 @@ int utf_codeLength(int sz, dchar c)
     return 1;
 }
 
-void utf_encodeChar(char* s, dchar c)
+void utf_encodeChar(char* s, dchar c) @system
 {
     assert(s !is null);
     assert(utf_isValidDchar(c));
@@ -367,7 +367,7 @@ void utf_encodeChar(char* s, dchar c)
         assert(0);
 }
 
-void utf_encodeWchar(wchar* s, dchar c)
+void utf_encodeWchar(wchar* s, dchar c) @system
 {
     assert(s !is null);
     assert(utf_isValidDchar(c));
@@ -382,7 +382,7 @@ void utf_encodeWchar(wchar* s, dchar c)
     }
 }
 
-void utf_encode(int sz, void* s, dchar c)
+void utf_encode(int sz, void* s, dchar c) @system
 {
     if (sz == 1)
         utf_encodeChar(cast(char*)s, c);
@@ -399,7 +399,7 @@ void utf_encode(int sz, void* s, dchar c)
  * Checks whether an Unicode code point is a bidirectional
  * control character.
  */
-@safe bool isBidiControl(dchar c)
+bool isBidiControl(dchar c)
 {
     // Source: https://www.unicode.org/versions/Unicode15.0.0, table 23-3.
     switch(c)
diff --git a/gcc/d/dmd/sapply.d b/gcc/d/dmd/sapply.d
index ef0151656b1..13fe6916531 100644
--- a/gcc/d/dmd/sapply.d
+++ b/gcc/d/dmd/sapply.d
@@ -37,7 +37,7 @@ private extern (C++) final class PostorderStatementVisitor : StoppableVisitor
 public:
     StoppableVisitor v;
 
-    extern (D) this(StoppableVisitor v) scope
+    extern (D) this(StoppableVisitor v) scope @safe
     {
         this.v = v;
     }
diff --git a/gcc/d/dmd/scope.h b/gcc/d/dmd/scope.h
index da114289850..3c4ae495265 100644
--- a/gcc/d/dmd/scope.h
+++ b/gcc/d/dmd/scope.h
@@ -10,6 +10,7 @@
 
 #pragma once
 
+class ErrorSink;
 class Identifier;
 class Module;
 class Statement;
@@ -85,6 +86,7 @@ struct Scope
     d_bool inLoop;                // true if inside a loop (where constructor calls aren't allowed)
     int intypeof;               // in typeof(exp)
     VarDeclaration *lastVar;    // Previous symbol used to prevent goto-skips-init
+    ErrorSink *eSink;           // sink for error messages
 
     /* If  minst && !tinst, it's in definitely non-speculative scope (eg. module member scope).
      * If !minst && !tinst, it's in definitely speculative scope (eg. template constraint).
diff --git a/gcc/d/dmd/semantic2.d b/gcc/d/dmd/semantic2.d
index 3cbf14f2b8f..53c8714510c 100644
--- a/gcc/d/dmd/semantic2.d
+++ b/gcc/d/dmd/semantic2.d
@@ -83,7 +83,7 @@ private extern(C++) final class Semantic2Visitor : Visitor
 {
     alias visit = Visitor.visit;
     Scope* sc;
-    this(Scope* sc) scope
+    this(Scope* sc) scope @safe
     {
         this.sc = sc;
     }
@@ -245,8 +245,9 @@ private extern(C++) final class Semantic2Visitor : Visitor
             return;
 
         //printf("VarDeclaration::semantic2('%s')\n", toChars());
+        sc = sc.push();
         sc.varDecl = vd;
-        scope(exit) sc.varDecl = null;
+        scope(exit) sc = sc.pop();
 
         if (vd.aliasTuple)        // if it's a tuple
         {
@@ -345,7 +346,7 @@ private extern(C++) final class Semantic2Visitor : Visitor
         // Note that modules get their own scope, from scratch.
         // This is so regardless of where in the syntax a module
         // gets imported, it is unaffected by context.
-        Scope* sc = Scope.createGlobal(mod); // create root scope
+        Scope* sc = Scope.createGlobal(mod, global.errorSink); // create root scope
         //printf("Module = %p\n", sc.scopesym);
         if (mod.members)
         {
diff --git a/gcc/d/dmd/semantic3.d b/gcc/d/dmd/semantic3.d
index c7d12194820..bff89f8eaf3 100644
--- a/gcc/d/dmd/semantic3.d
+++ b/gcc/d/dmd/semantic3.d
@@ -88,7 +88,7 @@ private extern(C++) final class Semantic3Visitor : Visitor
     alias visit = Visitor.visit;
 
     Scope* sc;
-    this(Scope* sc) scope
+    this(Scope* sc) scope @safe
     {
         this.sc = sc;
     }
@@ -193,7 +193,7 @@ private extern(C++) final class Semantic3Visitor : Visitor
         // Note that modules get their own scope, from scratch.
         // This is so regardless of where in the syntax a module
         // gets imported, it is unaffected by context.
-        Scope* sc = Scope.createGlobal(mod); // create root scope
+        Scope* sc = Scope.createGlobal(mod, global.errorSink); // create root scope
         //printf("Module = %p\n", sc.scopesym);
         if (mod.members)
         {
@@ -705,7 +705,7 @@ private extern(C++) final class Semantic3Visitor : Visitor
                     }
                     sc2.ctorflow.freeFieldinit();
 
-                    if (cd && !(sc2.ctorflow.callSuper & CSX.any_ctor) && cd.baseClass && cd.baseClass.ctor)
+                    if (cd && !(sc2.ctorflow.callSuper & (CSX.any_ctor | CSX.halt)) && cd.baseClass && cd.baseClass.ctor)
                     {
                         sc2.ctorflow.callSuper = CSX.none;
 
@@ -1423,7 +1423,7 @@ private extern(C++) final class Semantic3Visitor : Visitor
          */
         AggregateDeclaration ad = ctor.isMemberDecl();
         if (!ctor.fbody || !ad || !ad.fieldDtor ||
-	    global.params.dtorFields == FeatureState.disabled || !global.params.useExceptions || ctor.type.toTypeFunction.isnothrow)
+            global.params.dtorFields == FeatureState.disabled || !global.params.useExceptions || ctor.type.toTypeFunction.isnothrow)
             return visit(cast(FuncDeclaration)ctor);
 
         /* Generate:
@@ -1602,7 +1602,7 @@ private struct FuncDeclSem3
 
     // Scope of analysis
     Scope* sc;
-    this(FuncDeclaration fd,Scope* s) scope
+    this(FuncDeclaration fd,Scope* s) scope @safe
     {
         funcdecl = fd;
         sc = s;
diff --git a/gcc/d/dmd/sideeffect.d b/gcc/d/dmd/sideeffect.d
index 90b86df0418..30921c6b92c 100644
--- a/gcc/d/dmd/sideeffect.d
+++ b/gcc/d/dmd/sideeffect.d
@@ -37,7 +37,7 @@ extern (C++) bool isTrivialExp(Expression e)
     {
         alias visit = typeof(super).visit;
     public:
-        extern (D) this() scope
+        extern (D) this() scope @safe
         {
         }
 
@@ -75,7 +75,7 @@ extern (C++) bool hasSideEffect(Expression e, bool assumeImpureCalls = false)
     {
         alias visit = typeof(super).visit;
     public:
-        extern (D) this() scope
+        extern (D) this() scope @safe
         {
         }
 
diff --git a/gcc/d/dmd/statement.d b/gcc/d/dmd/statement.d
index 3ccf228d1e9..607dd51e087 100644
--- a/gcc/d/dmd/statement.d
+++ b/gcc/d/dmd/statement.d
@@ -84,7 +84,7 @@ extern (C++) abstract class Statement : ASTNode
         return DYNCAST.statement;
     }
 
-    final extern (D) this(const ref Loc loc, STMT stmt)
+    final extern (D) this(const ref Loc loc, STMT stmt) @safe
     {
         this.loc = loc;
         this.stmt = stmt;
@@ -129,7 +129,7 @@ extern (C++) abstract class Statement : ASTNode
         {
             va_list ap;
             va_start(ap, format);
-            .verror(loc, format, ap);
+            .verrorReport(loc, format, ap, ErrorKind.error);
             va_end(ap);
         }
 
@@ -137,7 +137,7 @@ extern (C++) abstract class Statement : ASTNode
         {
             va_list ap;
             va_start(ap, format);
-            .vwarning(loc, format, ap);
+            .verrorReport(loc, format, ap, ErrorKind.warning);
             va_end(ap);
         }
 
@@ -145,7 +145,7 @@ extern (C++) abstract class Statement : ASTNode
         {
             va_list ap;
             va_start(ap, format);
-            .vdeprecation(loc, format, ap);
+            .verrorReport(loc, format, ap, ErrorKind.deprecation);
             va_end(ap);
         }
     }
@@ -155,7 +155,7 @@ extern (C++) abstract class Statement : ASTNode
         {
             va_list ap;
             va_start(ap, format);
-            .verror(loc, format, ap);
+            .verrorReport(loc, format, ap, ErrorKind.error);
             va_end(ap);
         }
 
@@ -163,7 +163,7 @@ extern (C++) abstract class Statement : ASTNode
         {
             va_list ap;
             va_start(ap, format);
-            .vwarning(loc, format, ap);
+            .verrorReport(loc, format, ap, ErrorKind.warning);
             va_end(ap);
         }
 
@@ -171,7 +171,7 @@ extern (C++) abstract class Statement : ASTNode
         {
             va_list ap;
             va_start(ap, format);
-            .vdeprecation(loc, format, ap);
+            .verrorReport(loc, format, ap, ErrorKind.deprecation);
             va_end(ap);
         }
     }
@@ -447,7 +447,7 @@ extern (C++) final class PeelStatement : Statement
 {
     Statement s;
 
-    extern (D) this(Statement s)
+    extern (D) this(Statement s) @safe
     {
         super(s.loc, STMT.Peel);
         this.s = s;
@@ -467,25 +467,25 @@ extern (C++) class ExpStatement : Statement
 {
     Expression exp;
 
-    final extern (D) this(const ref Loc loc, Expression exp)
+    final extern (D) this(const ref Loc loc, Expression exp) @safe
     {
         super(loc, STMT.Exp);
         this.exp = exp;
     }
 
-    final extern (D) this(const ref Loc loc, Expression exp, STMT stmt)
+    final extern (D) this(const ref Loc loc, Expression exp, STMT stmt) @safe
     {
         super(loc, stmt);
         this.exp = exp;
     }
 
-    final extern (D) this(const ref Loc loc, Dsymbol declaration)
+    final extern (D) this(const ref Loc loc, Dsymbol declaration) @safe
     {
         super(loc, STMT.Exp);
         this.exp = new DeclarationExp(loc, declaration);
     }
 
-    static ExpStatement create(const ref Loc loc, Expression exp)
+    static ExpStatement create(const ref Loc loc, Expression exp) @safe
     {
         return new ExpStatement(loc, exp);
     }
@@ -508,7 +508,7 @@ extern (C++) final class DtorExpStatement : ExpStatement
     // Wraps an expression that is the destruction of 'var'
     VarDeclaration var;
 
-    extern (D) this(const ref Loc loc, Expression exp, VarDeclaration var)
+    extern (D) this(const ref Loc loc, Expression exp, VarDeclaration var) @safe
     {
         super(loc, exp, STMT.DtorExp);
         this.var = var;
@@ -540,7 +540,7 @@ extern (C++) final class MixinStatement : Statement
         this(loc, exps);
     }
 
-    extern (D) this(const ref Loc loc, Expressions* exps)
+    extern (D) this(const ref Loc loc, Expressions* exps) @safe
     {
         super(loc, STMT.Mixin);
         this.exps = exps;
@@ -571,13 +571,13 @@ extern (C++) class CompoundStatement : Statement
      *   loc = Instantiation information
      *   statements   = An array of `Statement`s, that will referenced by this class
      */
-    final extern (D) this(const ref Loc loc, Statements* statements)
+    final extern (D) this(const ref Loc loc, Statements* statements) @safe
     {
         super(loc, STMT.Compound);
         this.statements = statements;
     }
 
-    final extern (D) this(const ref Loc loc, Statements* statements, STMT stmt)
+    final extern (D) this(const ref Loc loc, Statements* statements, STMT stmt) @safe
     {
         super(loc, stmt);
         this.statements = statements;
@@ -649,7 +649,7 @@ extern (C++) class CompoundStatement : Statement
  */
 extern (C++) final class CompoundDeclarationStatement : CompoundStatement
 {
-    extern (D) this(const ref Loc loc, Statements* statements)
+    extern (D) this(const ref Loc loc, Statements* statements) @safe
     {
         super(loc, statements, STMT.CompoundDeclaration);
     }
@@ -678,7 +678,7 @@ extern (C++) final class UnrolledLoopStatement : Statement
 {
     Statements* statements;
 
-    extern (D) this(const ref Loc loc, Statements* statements)
+    extern (D) this(const ref Loc loc, Statements* statements) @safe
     {
         super(loc, STMT.UnrolledLoop);
         this.statements = statements;
@@ -717,7 +717,7 @@ extern (C++) final class ScopeStatement : Statement
     Statement statement;
     Loc endloc;                 // location of closing curly bracket
 
-    extern (D) this(const ref Loc loc, Statement statement, Loc endloc)
+    extern (D) this(const ref Loc loc, Statement statement, Loc endloc) @safe
     {
         super(loc, STMT.Scope);
         this.statement = statement;
@@ -767,7 +767,7 @@ extern (C++) final class ForwardingStatement : Statement
     /// The wrapped statement.
     Statement statement;
 
-    extern (D) this(const ref Loc loc, ForwardingScopeDsymbol sym, Statement statement)
+    extern (D) this(const ref Loc loc, ForwardingScopeDsymbol sym, Statement statement) @safe
     {
         super(loc, STMT.Forwarding);
         this.sym = sym;
@@ -775,7 +775,7 @@ extern (C++) final class ForwardingStatement : Statement
         this.statement = statement;
     }
 
-    extern (D) this(const ref Loc loc, Statement statement)
+    extern (D) this(const ref Loc loc, Statement statement) @safe
     {
         auto sym = new ForwardingScopeDsymbol();
         sym.symtab = new DsymbolTable();
@@ -804,7 +804,7 @@ extern (C++) final class WhileStatement : Statement
     Statement _body;
     Loc endloc;             // location of closing curly bracket
 
-    extern (D) this(const ref Loc loc, Expression condition, Statement _body, Loc endloc, Parameter param = null)
+    extern (D) this(const ref Loc loc, Expression condition, Statement _body, Loc endloc, Parameter param = null) @safe
     {
         super(loc, STMT.While);
         this.condition = condition;
@@ -846,7 +846,7 @@ extern (C++) final class DoStatement : Statement
     Expression condition;
     Loc endloc;                 // location of ';' after while
 
-    extern (D) this(const ref Loc loc, Statement _body, Expression condition, Loc endloc)
+    extern (D) this(const ref Loc loc, Statement _body, Expression condition, Loc endloc) @safe
     {
         super(loc, STMT.Do);
         this._body = _body;
@@ -894,7 +894,7 @@ extern (C++) final class ForStatement : Statement
     // treat that label as referring to this loop.
     Statement relatedLabeled;
 
-    extern (D) this(const ref Loc loc, Statement _init, Expression condition, Expression increment, Statement _body, Loc endloc)
+    extern (D) this(const ref Loc loc, Statement _init, Expression condition, Expression increment, Statement _body, Loc endloc) @safe
     {
         super(loc, STMT.For);
         this._init = _init;
@@ -955,7 +955,7 @@ extern (C++) final class ForeachStatement : Statement
     Statements* cases;          // put breaks, continues, gotos and returns here
     ScopeStatements* gotos;     // forward referenced goto's go here
 
-    extern (D) this(const ref Loc loc, TOK op, Parameters* parameters, Expression aggr, Statement _body, Loc endloc)
+    extern (D) this(const ref Loc loc, TOK op, Parameters* parameters, Expression aggr, Statement _body, Loc endloc) @safe
     {
         super(loc, STMT.Foreach);
         this.op = op;
@@ -1004,7 +1004,7 @@ extern (C++) final class ForeachRangeStatement : Statement
 
     VarDeclaration key;
 
-    extern (D) this(const ref Loc loc, TOK op, Parameter prm, Expression lwr, Expression upr, Statement _body, Loc endloc)
+    extern (D) this(const ref Loc loc, TOK op, Parameter prm, Expression lwr, Expression upr, Statement _body, Loc endloc) @safe
     {
         super(loc, STMT.ForeachRange);
         this.op = op;
@@ -1048,7 +1048,7 @@ extern (C++) final class IfStatement : Statement
     VarDeclaration match;   // for MatchExpression results
     Loc endloc;                 // location of closing curly bracket
 
-    extern (D) this(const ref Loc loc, Parameter prm, Expression condition, Statement ifbody, Statement elsebody, Loc endloc)
+    extern (D) this(const ref Loc loc, Parameter prm, Expression condition, Statement ifbody, Statement elsebody, Loc endloc) @safe
     {
         super(loc, STMT.If);
         this.prm = prm;
@@ -1093,7 +1093,7 @@ extern (C++) final class ConditionalStatement : Statement
     Statement ifbody;
     Statement elsebody;
 
-    extern (D) this(const ref Loc loc, Condition condition, Statement ifbody, Statement elsebody)
+    extern (D) this(const ref Loc loc, Condition condition, Statement ifbody, Statement elsebody) @safe
     {
         super(loc, STMT.Conditional);
         this.condition = condition;
@@ -1128,7 +1128,7 @@ extern (C++) final class StaticForeachStatement : Statement
 {
     StaticForeach sfe;
 
-    extern (D) this(const ref Loc loc, StaticForeach sfe)
+    extern (D) this(const ref Loc loc, StaticForeach sfe) @safe
     {
         super(loc, STMT.StaticForeach);
         this.sfe = sfe;
@@ -1154,7 +1154,7 @@ extern (C++) final class PragmaStatement : Statement
     Expressions* args;      // array of Expression's
     Statement _body;
 
-    extern (D) this(const ref Loc loc, const Identifier ident, Expressions* args, Statement _body)
+    extern (D) this(const ref Loc loc, const Identifier ident, Expressions* args, Statement _body) @safe
     {
         super(loc, STMT.Pragma);
         this.ident = ident;
@@ -1180,7 +1180,7 @@ extern (C++) final class StaticAssertStatement : Statement
 {
     StaticAssert sa;
 
-    extern (D) this(StaticAssert sa)
+    extern (D) this(StaticAssert sa) @safe
     {
         super(sa.loc, STMT.StaticAssert);
         this.sa = sa;
@@ -1291,7 +1291,7 @@ extern (C++) final class CaseStatement : Statement
     VarDeclaration lastVar;
     void* extra;            // for use by Statement_toIR()
 
-    extern (D) this(const ref Loc loc, Expression exp, Statement statement)
+    extern (D) this(const ref Loc loc, Expression exp, Statement statement) @safe
     {
         super(loc, STMT.Case);
         this.exp = exp;
@@ -1318,7 +1318,7 @@ extern (C++) final class CaseRangeStatement : Statement
     Expression last;
     Statement statement;
 
-    extern (D) this(const ref Loc loc, Expression first, Expression last, Statement statement)
+    extern (D) this(const ref Loc loc, Expression first, Expression last, Statement statement) @safe
     {
         super(loc, STMT.CaseRange);
         this.first = first;
@@ -1346,7 +1346,7 @@ extern (C++) final class DefaultStatement : Statement
 
     VarDeclaration lastVar;
 
-    extern (D) this(const ref Loc loc, Statement statement)
+    extern (D) this(const ref Loc loc, Statement statement) @safe
     {
         super(loc, STMT.Default);
         this.statement = statement;
@@ -1370,7 +1370,7 @@ extern (C++) final class GotoDefaultStatement : Statement
 {
     SwitchStatement sw;
 
-    extern (D) this(const ref Loc loc)
+    extern (D) this(const ref Loc loc) @safe
     {
         super(loc, STMT.GotoDefault);
     }
@@ -1395,7 +1395,7 @@ extern (C++) final class GotoCaseStatement : Statement
 
     CaseStatement cs;   // case statement it resolves to
 
-    extern (D) this(const ref Loc loc, Expression exp)
+    extern (D) this(const ref Loc loc, Expression exp) @safe
     {
         super(loc, STMT.GotoCase);
         this.exp = exp;
@@ -1418,12 +1418,12 @@ extern (C++) final class SwitchErrorStatement : Statement
 {
     Expression exp;
 
-    extern (D) this(const ref Loc loc)
+    extern (D) this(const ref Loc loc) @safe
     {
         super(loc, STMT.SwitchError);
     }
 
-    final extern (D) this(const ref Loc loc, Expression exp)
+    final extern (D) this(const ref Loc loc, Expression exp) @safe
     {
         super(loc, STMT.SwitchError);
         this.exp = exp;
@@ -1443,7 +1443,7 @@ extern (C++) final class ReturnStatement : Statement
     Expression exp;
     size_t caseDim;
 
-    extern (D) this(const ref Loc loc, Expression exp)
+    extern (D) this(const ref Loc loc, Expression exp) @safe
     {
         super(loc, STMT.Return);
         this.exp = exp;
@@ -1472,7 +1472,7 @@ extern (C++) final class BreakStatement : Statement
 {
     Identifier ident;
 
-    extern (D) this(const ref Loc loc, Identifier ident)
+    extern (D) this(const ref Loc loc, Identifier ident) @safe
     {
         super(loc, STMT.Break);
         this.ident = ident;
@@ -1496,7 +1496,7 @@ extern (C++) final class ContinueStatement : Statement
 {
     Identifier ident;
 
-    extern (D) this(const ref Loc loc, Identifier ident)
+    extern (D) this(const ref Loc loc, Identifier ident) @safe
     {
         super(loc, STMT.Continue);
         this.ident = ident;
@@ -1521,7 +1521,7 @@ extern (C++) final class SynchronizedStatement : Statement
     Expression exp;
     Statement _body;
 
-    extern (D) this(const ref Loc loc, Expression exp, Statement _body)
+    extern (D) this(const ref Loc loc, Expression exp, Statement _body) @safe
     {
         super(loc, STMT.Synchronized);
         this.exp = exp;
@@ -1559,7 +1559,7 @@ extern (C++) final class WithStatement : Statement
     VarDeclaration wthis;
     Loc endloc;
 
-    extern (D) this(const ref Loc loc, Expression exp, Statement _body, Loc endloc)
+    extern (D) this(const ref Loc loc, Expression exp, Statement _body, Loc endloc) @safe
     {
         super(loc, STMT.With);
         this.exp = exp;
@@ -1588,7 +1588,7 @@ extern (C++) final class TryCatchStatement : Statement
 
     Statement tryBody;   /// set to enclosing TryCatchStatement or TryFinallyStatement if in _body portion
 
-    extern (D) this(const ref Loc loc, Statement _body, Catches* catches)
+    extern (D) this(const ref Loc loc, Statement _body, Catches* catches) @safe
     {
         super(loc, STMT.TryCatch);
         this._body = _body;
@@ -1632,7 +1632,7 @@ extern (C++) final class Catch : RootObject
     // was generated by the compiler, wasn't present in source code
     bool internalCatch;
 
-    extern (D) this(const ref Loc loc, Type type, Identifier ident, Statement handler)
+    extern (D) this(const ref Loc loc, Type type, Identifier ident, Statement handler) @safe
     {
         //printf("Catch(%s, loc = %s)\n", id.toChars(), loc.toChars());
         this.loc = loc;
@@ -1660,7 +1660,7 @@ extern (C++) final class TryFinallyStatement : Statement
     Statement tryBody;   /// set to enclosing TryCatchStatement or TryFinallyStatement if in _body portion
     bool bodyFallsThru;  /// true if _body falls through to finally
 
-    extern (D) this(const ref Loc loc, Statement _body, Statement finalbody)
+    extern (D) this(const ref Loc loc, Statement _body, Statement finalbody) @safe
     {
         super(loc, STMT.TryFinally);
         this._body = _body;
@@ -1668,7 +1668,7 @@ extern (C++) final class TryFinallyStatement : Statement
         this.bodyFallsThru = true;      // assume true until statementSemantic()
     }
 
-    static TryFinallyStatement create(const ref Loc loc, Statement _body, Statement finalbody)
+    static TryFinallyStatement create(const ref Loc loc, Statement _body, Statement finalbody) @safe
     {
         return new TryFinallyStatement(loc, _body, finalbody);
     }
@@ -1702,7 +1702,7 @@ extern (C++) final class ScopeGuardStatement : Statement
     TOK tok;
     Statement statement;
 
-    extern (D) this(const ref Loc loc, TOK tok, Statement statement)
+    extern (D) this(const ref Loc loc, TOK tok, Statement statement) @safe
     {
         super(loc, STMT.ScopeGuard);
         this.tok = tok;
@@ -1730,7 +1730,7 @@ extern (C++) final class ThrowStatement : Statement
     // was generated by the compiler, wasn't present in source code
     bool internalThrow;
 
-    extern (D) this(const ref Loc loc, Expression exp)
+    extern (D) this(const ref Loc loc, Expression exp) @safe
     {
         super(loc, STMT.Throw);
         this.exp = exp;
@@ -1755,7 +1755,7 @@ extern (C++) final class DebugStatement : Statement
 {
     Statement statement;
 
-    extern (D) this(const ref Loc loc, Statement statement)
+    extern (D) this(const ref Loc loc, Statement statement) @safe
     {
         super(loc, STMT.Debug);
         this.statement = statement;
@@ -1785,7 +1785,7 @@ extern (C++) final class GotoStatement : Statement
     VarDeclaration lastVar;
     bool inCtfeBlock;               /// set if goto is inside an `if (__ctfe)` block
 
-    extern (D) this(const ref Loc loc, Identifier ident)
+    extern (D) this(const ref Loc loc, Identifier ident) @safe
     {
         super(loc, STMT.Goto);
         this.ident = ident;
@@ -1900,7 +1900,7 @@ extern (C++) final class LabelStatement : Statement
     bool breaks;                // someone did a 'break ident'
     bool inCtfeBlock;           // inside a block dominated by `if (__ctfe)`
 
-    extern (D) this(const ref Loc loc, Identifier ident, Statement statement)
+    extern (D) this(const ref Loc loc, Identifier ident, Statement statement) @safe
     {
         super(loc, STMT.Label);
         this.ident = ident;
@@ -1927,12 +1927,16 @@ extern (C++) final class LabelDsymbol : Dsymbol
     bool deleted;           // set if rewritten to return in foreach delegate
     bool iasm;              // set if used by inline assembler
 
-    extern (D) this(Identifier ident, const ref Loc loc = Loc.initial)
+    // set if label was defined multiple times, to avoid duplicate errors
+    // can be removed if generic error message deduplication is implemented
+    bool duplicated;
+
+    extern (D) this(Identifier ident, const ref Loc loc = Loc.initial) @safe
     {
         super(loc, ident);
     }
 
-    static LabelDsymbol create(Identifier ident)
+    static LabelDsymbol create(Identifier ident) @safe
     {
         return new LabelDsymbol(ident);
     }
@@ -1956,13 +1960,13 @@ extern (C++) class AsmStatement : Statement
 {
     Token* tokens;
 
-    extern (D) this(const ref Loc loc, Token* tokens)
+    extern (D) this(const ref Loc loc, Token* tokens) @safe
     {
         super(loc, STMT.Asm);
         this.tokens = tokens;
     }
 
-    extern (D) this(const ref Loc loc, Token* tokens, STMT stmt)
+    extern (D) this(const ref Loc loc, Token* tokens, STMT stmt) @safe
     {
         super(loc, stmt);
         this.tokens = tokens;
@@ -1990,7 +1994,7 @@ extern (C++) final class InlineAsmStatement : AsmStatement
     bool refparam;  // true if function parameter is referenced
     bool naked;     // true if function is to be naked
 
-    extern (D) this(const ref Loc loc, Token* tokens)
+    extern (D) this(const ref Loc loc, Token* tokens) @safe
     {
         super(loc, tokens, STMT.InlineAsm);
     }
@@ -2022,7 +2026,7 @@ extern (C++) final class GccAsmStatement : AsmStatement
     Identifiers* labels;        // list of goto labels
     GotoStatements* gotos;      // of the goto labels, the equivalent statements they represent
 
-    extern (D) this(const ref Loc loc, Token* tokens)
+    extern (D) this(const ref Loc loc, Token* tokens) @safe
     {
         super(loc, tokens, STMT.GccAsm);
     }
@@ -2045,7 +2049,7 @@ extern (C++) final class CompoundAsmStatement : CompoundStatement
 {
     StorageClass stc; // postfix attributes like nothrow/pure/@trusted
 
-    extern (D) this(const ref Loc loc, Statements* statements, StorageClass stc)
+    extern (D) this(const ref Loc loc, Statements* statements, StorageClass stc) @safe
     {
         super(loc, statements, STMT.CompoundAsm);
         this.stc = stc;
@@ -2074,7 +2078,7 @@ extern (C++) final class ImportStatement : Statement
 {
     Dsymbols* imports;      // Array of Import's
 
-    extern (D) this(const ref Loc loc, Dsymbols* imports)
+    extern (D) this(const ref Loc loc, Dsymbols* imports) @safe
     {
         super(loc, STMT.Import);
         this.imports = imports;
@@ -2157,7 +2161,7 @@ mixin template VisitStatement(Result)
  *      handler = string for the name of the visit handler
  * Returns: boilerplate code for a case
  */
-pure string visitStmtCase(string handler)
+pure string visitStmtCase(string handler) @safe
 {
     if (__ctfe)
     {
diff --git a/gcc/d/dmd/statement.h b/gcc/d/dmd/statement.h
index b7403b5d8ad..eb4849dfc1b 100644
--- a/gcc/d/dmd/statement.h
+++ b/gcc/d/dmd/statement.h
@@ -699,6 +699,7 @@ public:
 
     d_bool deleted;           // set if rewritten to return in foreach delegate
     d_bool iasm;              // set if used by inline assembler
+    d_bool duplicated;        // set if multiply defined, to avoid duplicate error messages
 
     static LabelDsymbol *create(Identifier *ident);
     LabelDsymbol *isLabel() override;
diff --git a/gcc/d/dmd/statementsem.d b/gcc/d/dmd/statementsem.d
index 2def2539597..178cef5af8c 100644
--- a/gcc/d/dmd/statementsem.d
+++ b/gcc/d/dmd/statementsem.d
@@ -21,7 +21,6 @@ import dmd.arrayop;
 import dmd.arraytypes;
 import dmd.astcodegen;
 import dmd.astenums;
-import dmd.ast_node;
 import dmd.attrib;
 import dmd.blockexit;
 import dmd.clone;
@@ -39,7 +38,6 @@ import dmd.dsymbol;
 import dmd.dsymbolsem;
 import dmd.dtemplate;
 import dmd.errors;
-import dmd.errorsink;
 import dmd.escape;
 import dmd.expression;
 import dmd.expressionsem;
@@ -57,7 +55,6 @@ import dmd.mustuse;
 import dmd.nogc;
 import dmd.opover;
 import dmd.parse;
-import dmd.printast;
 import dmd.common.outbuffer;
 import dmd.root.string;
 import dmd.semantic2;
@@ -68,7 +65,6 @@ import dmd.target;
 import dmd.tokens;
 import dmd.typesem;
 import dmd.visitor;
-import dmd.compiler;
 
 version (DMDLIB)
 {
@@ -109,7 +105,7 @@ private Identifier fixupLabelName(Scope* sc, Identifier ident)
  * Returns:
  *      if `true`, then the `LabelStatement`, otherwise `null`
  */
-private LabelStatement checkLabeledLoop(Scope* sc, Statement statement)
+private LabelStatement checkLabeledLoop(Scope* sc, Statement statement) @safe
 {
     if (sc.slabel && sc.slabel.statement == statement)
     {
@@ -142,6 +138,8 @@ private Expression checkAssignmentAsCondition(Expression e, Scope* sc)
 // Performs semantic analysis in Statement AST nodes
 extern(C++) Statement statementSemantic(Statement s, Scope* sc)
 {
+    import dmd.compiler;
+
     version (CallbackAPI)
         Compiler.onStatementSemanticStart(s, sc);
 
@@ -2758,6 +2756,12 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
                 {
                     if (e0)
                         rs.error("expected return type of `%s`, not `%s`", tret.toChars(), resType.toChars());
+                    else if (tbret.isTypeNoreturn())
+                    {
+                        rs.error("cannot return from `noreturn` function");
+                        .errorSupplemental(rs.loc,
+                            "Consider adding an endless loop, `assert(0)`, or another `noreturn` expression");
+                    }
                     else
                         rs.error("`return` expression expected");
                 }
@@ -3547,9 +3551,19 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
         ls.inCtfeBlock = (sc.flags & SCOPE.ctfeBlock) != 0;
 
         LabelDsymbol ls2 = fd.searchLabel(ls.ident, ls.loc);
-        if (ls2.statement)
+        if (ls2.statement && !ls2.duplicated)
         {
-            ls.error("label `%s` already defined", ls2.toChars());
+            if (ls.loc == ls2.loc)
+            {
+                ls2.duplicated = true;
+                ls.error("label `%s` is duplicated", ls2.toChars());
+                .errorSupplemental(ls2.loc, "labels cannot be used in a static foreach with more than 1 iteration");
+            }
+            else
+            {
+                ls.error("label `%s` is already defined", ls2.toChars());
+                .errorSupplemental(ls2.loc, "first definition is here");
+            }
             return setError();
         }
         else
@@ -4068,8 +4082,8 @@ void catchSemantic(Catch c, Scope* sc)
     }
     else if (!c.type.isNaked() && !c.type.isConst())
     {
-        // @@@DEPRECATED_2.113@@@
-        // Deprecated in 2.103, change into an error & uncomment in 2.113
+        // @@@DEPRECATED_2.115@@@
+        // Deprecated in 2.105, change into an error & uncomment assign in 2.115
         deprecation(c.loc, "can only catch mutable or const qualified types, not `%s`", c.type.toChars());
         //c.errors = true;
     }
diff --git a/gcc/d/dmd/target.d b/gcc/d/dmd/target.d
index 81ff84f361e..aba3319247b 100644
--- a/gcc/d/dmd/target.d
+++ b/gcc/d/dmd/target.d
@@ -159,7 +159,7 @@ extern (C++) struct Target
      * This can be used to restore the state set by `_init` to its original
      * state.
      */
-    void deinitialize()
+    void deinitialize() @safe
     {
         this = this.init;
     }
@@ -203,7 +203,7 @@ extern (C++) struct Target
      *      2   vector element type is not supported
      *      3   vector size is not supported
      */
-    extern (C++) int isVectorTypeSupported(int sz, Type type);
+    extern (C++) int isVectorTypeSupported(int sz, Type type) @safe;
 
     /**
      * Checks whether the target supports the given operation for vectors.
@@ -221,7 +221,7 @@ extern (C++) struct Target
      * Returns:
      *      `LINK` to use for `extern(System)`
      */
-    extern (C++) LINK systemLinkage();
+    extern (C++) LINK systemLinkage() @safe;
 
     /**
      * Describes how an argument type is passed to a function on target.
@@ -270,7 +270,7 @@ extern (C++) struct Target
      *  tf = type of function being called
      * Returns: `true` if the callee invokes destructors for arguments.
      */
-    extern (C++) bool isCalleeDestroyingArgs(TypeFunction tf);
+    extern (C++) bool isCalleeDestroyingArgs(TypeFunction tf) @safe;
 
     /**
      * Returns true if the implementation for object monitors is always defined
@@ -288,7 +288,7 @@ extern (C++) struct Target
      * Returns:
      *      `false` if the target does not support `pragma(linkerDirective)`.
      */
-    extern (C++) bool supportsLinkerDirective() const;
+    extern (C++) bool supportsLinkerDirective() const @safe;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
diff --git a/gcc/d/dmd/templateparamsem.d b/gcc/d/dmd/templateparamsem.d
index 1a9d2520c84..6b8f949f526 100644
--- a/gcc/d/dmd/templateparamsem.d
+++ b/gcc/d/dmd/templateparamsem.d
@@ -50,7 +50,7 @@ private extern (C++) final class TemplateParameterSemanticVisitor : Visitor
     TemplateParameters* parameters;
     bool result;
 
-    this(Scope* sc, TemplateParameters* parameters) scope
+    this(Scope* sc, TemplateParameters* parameters) scope @safe
     {
         this.sc = sc;
         this.parameters = parameters;
diff --git a/gcc/d/dmd/tokens.d b/gcc/d/dmd/tokens.d
index 58717625cac..950c830cb33 100644
--- a/gcc/d/dmd/tokens.d
+++ b/gcc/d/dmd/tokens.d
@@ -898,7 +898,7 @@ extern (C++) struct Token
 
 nothrow:
 
-    int isKeyword() const
+    int isKeyword() const @safe
     {
         foreach (kw; keywords)
         {
diff --git a/gcc/d/dmd/typesem.d b/gcc/d/dmd/typesem.d
index d0923953663..a80aa80a89d 100644
--- a/gcc/d/dmd/typesem.d
+++ b/gcc/d/dmd/typesem.d
@@ -530,12 +530,10 @@ extern(C++) Type typeSemantic(Type type, const ref Loc loc, Scope* sc)
             }
 
             RootObject o = (*tup.objects)[cast(size_t)d];
-            if (o.dyncast() != DYNCAST.type)
-            {
-                .error(loc, "`%s` is not a type", mtype.toChars());
-                return error();
-            }
-            return (cast(Type)o).addMod(mtype.mod);
+            if (auto tt = o.isType())
+                return tt.addMod(mtype.mod);
+            .error(loc, "`%s` is not a type", mtype.toChars());
+            return error();
         }
 
         if (t && t.ty == Terror)
@@ -2006,7 +2004,7 @@ extern (C++) Type merge(Type type)
         OutBuffer buf;
         buf.reserve(32);
 
-        mangleToBuffer(type, &buf);
+        mangleToBuffer(type, buf);
 
         auto sv = type.stringtable.update(buf[]);
         if (sv.value)
@@ -5015,7 +5013,10 @@ RootObject compileTypeMixin(TypeMixin tm, ref const Loc loc, Scope* sc)
     }
     if (p.token.value != TOK.endOfFile)
     {
-        .error(loc, "incomplete mixin type `%s`", str.ptr);
+        .error(loc, "unexpected token `%s` after type `%s`",
+            p.token.toChars(), o.toChars());
+        .errorSupplemental(loc, "while parsing string mixin type `%s`",
+            str.ptr);
         return null;
     }
 
diff --git a/gcc/d/dmd/visitor.d b/gcc/d/dmd/visitor.d
index 7b059a061fd..591d3c0c3b4 100644
--- a/gcc/d/dmd/visitor.d
+++ b/gcc/d/dmd/visitor.d
@@ -255,7 +255,7 @@ extern (C++) class StoppableVisitor : Visitor
 public:
     bool stop;
 
-    final extern (D) this() scope
+    final extern (D) this() scope @safe
     {
     }
 }
diff --git a/gcc/d/intrinsics.cc b/gcc/d/intrinsics.cc
index aaf04e50baa..583d5a9dea6 100644
--- a/gcc/d/intrinsics.cc
+++ b/gcc/d/intrinsics.cc
@@ -123,7 +123,7 @@ maybe_set_intrinsic (FuncDeclaration *decl)
 	    return;
 
 	  OutBuffer buf;
-	  mangleToBuffer (fd->type, &buf);
+	  mangleToBuffer (fd->type, buf);
 	  tdeco = buf.extractChars ();
 	}
 
diff --git a/gcc/testsuite/gdc.test/compilable/test23145.d b/gcc/testsuite/gdc.test/compilable/test23145.d
index 45235dc5284..18eabfb51b5 100644
--- a/gcc/testsuite/gdc.test/compilable/test23145.d
+++ b/gcc/testsuite/gdc.test/compilable/test23145.d
@@ -1,8 +1,9 @@
-/* TEST_OUTPUT:
+/* REQUIRED_ARGS: -wo -wi
+TEST_OUTPUT:
 ---
-compilable/test23145.d(117): Deprecation: `scope` allocation of `c` requires that constructor be annotated with `scope`
+compilable/test23145.d(117): Warning: `scope` allocation of `c` requires that constructor be annotated with `scope`
 compilable/test23145.d(111):        is the location of the constructor
-compilable/test23145.d(124): Deprecation: `scope` allocation of `c` requires that constructor be annotated with `scope`
+compilable/test23145.d(124): Warning: `scope` allocation of `c` requires that constructor be annotated with `scope`
 compilable/test23145.d(111):        is the location of the constructor
 ---
 */
@@ -24,7 +25,7 @@ class C
     this(D d) @safe @nogc;
 }
 
-C foo(D d)@nogc @safe
+C foo(D d) @nogc @safe
 {
     scope e = new C(1);  // ok
     scope c = new C(d);  // deprecation
@@ -37,3 +38,8 @@ C bax(D d) @safe
     scope c = new C(d);  // deprecation
     return c.d.c;
 }
+
+void inferred(D d)
+{
+    scope c = new C(d);  // ok
+}
diff --git a/gcc/testsuite/gdc.test/fail_compilation/biterrors3.d b/gcc/testsuite/gdc.test/fail_compilation/biterrors3.d
index c5031a4db10..09d7be66d64 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/biterrors3.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/biterrors3.d
@@ -3,8 +3,8 @@
 ---
 fail_compilation/biterrors3.d(103): Error: storage class not allowed for bit-field declaration
 fail_compilation/biterrors3.d(106): Error: expected `,` or `=` after identifier, not `:`
-fail_compilation/biterrors3.d(106): Error: `:` is not a valid attribute for enum members
-fail_compilation/biterrors3.d(106): Error: `3` is not a valid attribute for enum members
+fail_compilation/biterrors3.d(106): Error: found `:` when expecting `,`
+fail_compilation/biterrors3.d(106): Error: found `3` when expecting `identifier`
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/fail_compilation/bug8891.d b/gcc/testsuite/gdc.test/fail_compilation/bug8891.d
index e7316c31723..7b927f97007 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/bug8891.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/bug8891.d
@@ -1,7 +1,7 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/bug8891.d(21): Error: need `this` for `opCall` of type `S(int n)`
+fail_compilation/bug8891.d(21): Error: calling non-static function `opCall` requires an instance of type `S`
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/fail_compilation/deprecatedinref.d b/gcc/testsuite/gdc.test/fail_compilation/deprecatedinref.d
deleted file mode 100644
index 20c3666bef1..00000000000
--- a/gcc/testsuite/gdc.test/fail_compilation/deprecatedinref.d
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
-REQUIRED_ARGS: -de
-TEST_OUTPUT:
----
-fail_compilation/deprecatedinref.d(9): Deprecation: using `in ref` is deprecated, use `-preview=in` and `in` instead
-fail_compilation/deprecatedinref.d(10): Deprecation: using `ref in` is deprecated, use `-preview=in` and `in` instead
----
-*/
-void foo(in ref int);
-void foor(ref in int);
diff --git a/gcc/testsuite/gdc.test/fail_compilation/diag15209.d b/gcc/testsuite/gdc.test/fail_compilation/diag15209.d
index 9a4f396d957..bd6d723437e 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/diag15209.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/diag15209.d
@@ -1,8 +1,8 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/diag15209.d(18): Error: need `this` for `x` of type `int`
-fail_compilation/diag15209.d(21): Error: need `this` for `x` of type `int`
+fail_compilation/diag15209.d(18): Error: accessing non-static variable `x` requires an instance of `C1`
+fail_compilation/diag15209.d(21): Error: accessing non-static variable `x` requires an instance of `S2`
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/fail_compilation/diag9451.d b/gcc/testsuite/gdc.test/fail_compilation/diag9451.d
index ffec627f02f..980c6897aa2 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/diag9451.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/diag9451.d
@@ -1,11 +1,12 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/diag9451.d(26): Error: cannot create instance of abstract class `C2`
-fail_compilation/diag9451.d(26):        function `void f1()` is not implemented
-fail_compilation/diag9451.d(26):        function `void f2(int)` is not implemented
-fail_compilation/diag9451.d(26):        function `void f2(float) const` is not implemented
-fail_compilation/diag9451.d(26):        function `int f2(float) pure` is not implemented
+fail_compilation/diag9451.d(27): Error: cannot create instance of abstract class `C2`
+fail_compilation/diag9451.d(21):        class `C2` is declared here
+fail_compilation/diag9451.d(15):        function `void f1()` is not implemented
+fail_compilation/diag9451.d(16):        function `void f2(int)` is not implemented
+fail_compilation/diag9451.d(17):        function `void f2(float) const` is not implemented
+fail_compilation/diag9451.d(18):        function `int f2(float) pure` is not implemented
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/fail_compilation/diag9635.d b/gcc/testsuite/gdc.test/fail_compilation/diag9635.d
index fe142adc847..9794c8f51e6 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/diag9635.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/diag9635.d
@@ -2,8 +2,8 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/diag9635.d(17): Error: need `this` for `i` of type `int`
-fail_compilation/diag9635.d(18): Error: need `this` for `foo` of type `pure nothrow @nogc @safe void()`
+fail_compilation/diag9635.d(17): Error: accessing non-static variable `i` requires an instance of `Foo`
+fail_compilation/diag9635.d(18): Error: calling non-static function `foo` requires an instance of type `Foo`
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/fail_compilation/dip1000_deprecation.d b/gcc/testsuite/gdc.test/fail_compilation/dip1000_deprecation.d
index 61174395be3..e591a1428a5 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/dip1000_deprecation.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/dip1000_deprecation.d
@@ -1,5 +1,5 @@
 /*
-REQUIRED_ARGS: -de
+REQUIRED_ARGS: -de -wo
 TEST_OUTPUT:
 ---
 fail_compilation/dip1000_deprecation.d(20): Deprecation: `@safe` function `main` calling `inferred`
@@ -9,17 +9,17 @@ fail_compilation/dip1000_deprecation.d(22): Deprecation: `@safe` function `main`
 fail_compilation/dip1000_deprecation.d(39):        which calls `dip1000_deprecation.inferred`
 fail_compilation/dip1000_deprecation.d(28):        which wouldn't be `@safe` because of:
 fail_compilation/dip1000_deprecation.d(28):        scope variable `x0` may not be returned
-fail_compilation/dip1000_deprecation.d(54): Deprecation: escaping reference to stack allocated value returned by `S(null)`
-fail_compilation/dip1000_deprecation.d(55): Deprecation: escaping reference to stack allocated value returned by `createS()`
-fail_compilation/dip1000_deprecation.d(58): Deprecation: returning `s.incorrectReturnRef()` escapes a reference to local variable `s`
+fail_compilation/dip1000_deprecation.d(54): Warning: escaping reference to stack allocated value returned by `S(null)`
+fail_compilation/dip1000_deprecation.d(55): Warning: escaping reference to stack allocated value returned by `createS()`
+fail_compilation/dip1000_deprecation.d(58): Warning: returning `s.incorrectReturnRef()` escapes a reference to local variable `s`
 ---
 */
 
 void main() @safe
 {
-    inferred();
-    inferredB(); // no deprecation, trusted
-    inferredC(); // nested deprecation
+    cast(void)inferred();
+    cast(void)inferredB(); // no deprecation, trusted
+    cast(void)inferredC(); // nested deprecation
 }
 
 auto inferred()
@@ -49,10 +49,10 @@ struct S
 
 S createS() { return S.init; }
 
-int* escape()
+int* escape(int i)
 {
-    return S().incorrectReturnRef();
-    return createS().incorrectReturnRef();
+    if (i) return S().incorrectReturnRef();
+    if (i) return createS().incorrectReturnRef();
 
     S s;
     return s.incorrectReturnRef();
diff --git a/gcc/testsuite/gdc.test/fail_compilation/e15876_6.d b/gcc/testsuite/gdc.test/fail_compilation/e15876_6.d
index 7547b387dff..6b060fd69ee 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/e15876_6.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/e15876_6.d
@@ -1,7 +1,7 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/e15876_6.d(7): Error: identifier expected following `(type)`.
+fail_compilation/e15876_6.d(7): Error: identifier expected following `immutable(int).`, not `;`
 ---
 */
 auto unaryExParseError = immutable(int).;
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail10285.d b/gcc/testsuite/gdc.test/fail_compilation/fail10285.d
index c88e30688f7..108712533d2 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail10285.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail10285.d
@@ -1,11 +1,14 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/fail10285.d(13): Error: no identifier for declarator `int`
-fail_compilation/fail10285.d(14): Error: expected `,` or `=` after identifier, not `y`
-fail_compilation/fail10285.d(15): Error: expected identifier after type, not `bool`
-fail_compilation/fail10285.d(16): Error: expected identifier after type, not `int`
-fail_compilation/fail10285.d(18): Error: initializer required after `z` when type is specified
+fail_compilation/fail10285.d(16): Error: no identifier for declarator `int`
+fail_compilation/fail10285.d(17): Error: expected `,` or `=` after identifier, not `y`
+fail_compilation/fail10285.d(17): Error: initializer required after `x` when type is specified
+fail_compilation/fail10285.d(18): Error: no identifier for declarator `int`
+fail_compilation/fail10285.d(18): Error: found `bool` when expecting `,`
+fail_compilation/fail10285.d(19): Error: no identifier for declarator `j`
+fail_compilation/fail10285.d(19): Error: found `int` when expecting `,`
+fail_compilation/fail10285.d(21): Error: initializer required after `z` when type is specified
 ---
 */
 enum
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail11545.d b/gcc/testsuite/gdc.test/fail_compilation/fail11545.d
index a576817238f..01d8e93d569 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail11545.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail11545.d
@@ -1,8 +1,8 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/fail11545.d(14): Error: need `this` for `x` of type `int`
-fail_compilation/fail11545.d(18): Error: need `this` for `x` of type `int`
+fail_compilation/fail11545.d(14): Error: accessing non-static variable `x` requires an instance of `C`
+fail_compilation/fail11545.d(18): Error: accessing non-static variable `x` requires an instance of `C`
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail120.d b/gcc/testsuite/gdc.test/fail_compilation/fail120.d
index c9d67a491d8..f9ede04fb5d 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail120.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail120.d
@@ -1,8 +1,8 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/fail120.d(12): Error: need `this` for `nodes` of type `int[2]`
-fail_compilation/fail120.d(13): Error: need `this` for `nodes` of type `int[2]`
+fail_compilation/fail120.d(12): Error: accessing non-static variable `nodes` requires an instance of `Foo`
+fail_compilation/fail120.d(13): Error: accessing non-static variable `nodes` requires an instance of `Foo`
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail142.d b/gcc/testsuite/gdc.test/fail_compilation/fail142.d
index 343b2e3c731..c31a317500a 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail142.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail142.d
@@ -1,8 +1,9 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/fail142.d(20): Error: cannot create instance of abstract class `B`
-fail_compilation/fail142.d(20):        function `void test()` is not implemented
+fail_compilation/fail142.d(21): Error: cannot create instance of abstract class `B`
+fail_compilation/fail142.d(15):        class `B` is declared here
+fail_compilation/fail142.d(12):        function `void test()` is not implemented
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail143.d b/gcc/testsuite/gdc.test/fail_compilation/fail143.d
index 6df232f68a1..e5ccb0fcb06 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail143.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail143.d
@@ -1,7 +1,7 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/fail143.d(23): Error: need `this` for `next` of type `uint()`
+fail_compilation/fail143.d(23): Error: calling non-static function `next` requires an instance of type `Quux`
 fail_compilation/fail143.d(30): Error: template instance `fail143.Foo!int` error instantiating
 ---
 */
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail144.d b/gcc/testsuite/gdc.test/fail_compilation/fail144.d
index 6e73d3bea86..4977e4d86d4 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail144.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail144.d
@@ -1,7 +1,7 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/fail144.d(13): Error: `"message"`
+fail_compilation/fail144.d(13): Error: message
 fail_compilation/fail144.d(26):        called from here: `bar(7)`
 ---
 */
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail145.d b/gcc/testsuite/gdc.test/fail_compilation/fail145.d
index 5a7a4ca2228..1e90237d0c3 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail145.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail145.d
@@ -2,7 +2,7 @@
 REQUIRED_ARGS: -checkaction=context
 TEST_OUTPUT:
 ---
-fail_compilation/fail145.d(14): Error: `"assert(i && (i < 0)) failed"`
+fail_compilation/fail145.d(14): Error: `assert(i && (i < 0))` failed
 fail_compilation/fail145.d(27):        called from here: `bar(7)`
 ---
 */
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail17955.d b/gcc/testsuite/gdc.test/fail_compilation/fail17955.d
index 08329194228..43ce5cc42fc 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail17955.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail17955.d
@@ -2,19 +2,20 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/fail17955.d(81): Error: cannot create instance of abstract class `SimpleTimeZone`
-fail_compilation/fail17955.d(81):        function `bool hasDST()` is not implemented
-fail_compilation/fail17955.d(93): Error: template instance `fail17955.SimpleTimeZone.fromISOExtString!dstring` error instantiating
-fail_compilation/fail17955.d(25):        instantiated from here: `fromISOExtString!string`
-fail_compilation/fail17955.d(56):        instantiated from here: `isISOExtStringSerializable!(SysTime)`
-fail_compilation/fail17955.d(49):        instantiated from here: `toRedis!(SysTime)`
-fail_compilation/fail17955.d(40):        ... (2 instantiations, -v to show) ...
-fail_compilation/fail17955.d(32):        instantiated from here: `indicesOf!(isRedisType, resetCodeExpireTime)`
-fail_compilation/fail17955.d(67):        instantiated from here: `RedisStripped!(User, true)`
-fail_compilation/fail17955.d(93): Error: need `this` for `fromISOExtString` of type `pure nothrow @nogc @safe immutable(SimpleTimeZone)(dstring __param_0)`
-fail_compilation/fail17955.d(95): Error: undefined identifier `DateTimeException`
-fail_compilation/fail17955.d(25): Error: variable `fail17955.isISOExtStringSerializable!(SysTime).isISOExtStringSerializable` - type `void` is inferred from initializer `fromISOExtString("")`, and variables cannot be of type `void`
-fail_compilation/fail17955.d(54): Error: function `fail17955.toRedis!(SysTime).toRedis` has no `return` statement, but is expected to return a value of type `string`
+fail_compilation/fail17955.d(82): Error: cannot create instance of abstract class `SimpleTimeZone`
+fail_compilation/fail17955.d(76):        class `SimpleTimeZone` is declared here
+fail_compilation/fail17955.d(73):        function `bool hasDST()` is not implemented
+fail_compilation/fail17955.d(94): Error: template instance `fail17955.SimpleTimeZone.fromISOExtString!dstring` error instantiating
+fail_compilation/fail17955.d(26):        instantiated from here: `fromISOExtString!string`
+fail_compilation/fail17955.d(57):        instantiated from here: `isISOExtStringSerializable!(SysTime)`
+fail_compilation/fail17955.d(50):        instantiated from here: `toRedis!(SysTime)`
+fail_compilation/fail17955.d(41):        ... (2 instantiations, -v to show) ...
+fail_compilation/fail17955.d(33):        instantiated from here: `indicesOf!(isRedisType, resetCodeExpireTime)`
+fail_compilation/fail17955.d(68):        instantiated from here: `RedisStripped!(User, true)`
+fail_compilation/fail17955.d(94): Error: calling non-static function `fromISOExtString` requires an instance of type `SimpleTimeZone`
+fail_compilation/fail17955.d(96): Error: undefined identifier `DateTimeException`
+fail_compilation/fail17955.d(26): Error: variable `fail17955.isISOExtStringSerializable!(SysTime).isISOExtStringSerializable` - type `void` is inferred from initializer `fromISOExtString("")`, and variables cannot be of type `void`
+fail_compilation/fail17955.d(55): Error: function `fail17955.toRedis!(SysTime).toRedis` has no `return` statement, but is expected to return a value of type `string`
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail20538.d b/gcc/testsuite/gdc.test/fail_compilation/fail20538.d
index df7f142e275..e07af6cf165 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail20538.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail20538.d
@@ -1,8 +1,9 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/fail20538.d(12): Error: assignment must be preceded by an identifier
-fail_compilation/fail20538.d(12): Error: found `1` when expecting `,`
+fail_compilation/fail20538.d(13): Error: found `=` when expecting `identifier`
+fail_compilation/fail20538.d(13): Error: found `1` when expecting `identifier`
+fail_compilation/fail20538.d(14): Error: named enum cannot declare member with type
 ---
 */
 
@@ -10,5 +11,6 @@ enum smth
 {
     a,
     = 1,
+    int x = 1,
     @disable b
 }
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail25.d b/gcc/testsuite/gdc.test/fail_compilation/fail25.d
index 11c0f0be3d8..abb795e04fb 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail25.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail25.d
@@ -1,7 +1,7 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/fail25.d(14): Error: need `this` for `yuiop` of type `int`
+fail_compilation/fail25.d(14): Error: accessing non-static variable `yuiop` requires an instance of `Qwert`
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail301.d b/gcc/testsuite/gdc.test/fail_compilation/fail301.d
index bf90f55507b..f527819559a 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail301.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail301.d
@@ -1,7 +1,7 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/fail301.d(11): Error: need `this` for `guard` of type `int`
+fail_compilation/fail301.d(11): Error: accessing non-static variable `guard` requires an instance of `bug3305b`
 fail_compilation/fail301.d(22): Error: template instance `fail301.bug3305!0` error instantiating
 ---
 */
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail46.d b/gcc/testsuite/gdc.test/fail_compilation/fail46.d
index 9401b921862..9d97ba12614 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail46.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail46.d
@@ -2,7 +2,7 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/fail46.d(19): Error: need `this` for `bug` of type `int()`
+fail_compilation/fail46.d(19): Error: calling non-static function `bug` requires an instance of type `MyStruct`
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail4923.d b/gcc/testsuite/gdc.test/fail_compilation/fail4923.d
index 3239cff0cf0..836b14ac674 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail4923.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail4923.d
@@ -1,13 +1,17 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/fail4923.d(4): Error: immutable variable `bar` initialization is not allowed in `static this`
-fail_compilation/fail4923.d(4):        Use `shared static this` instead.
+fail_compilation/fail4923.d(5): Error: immutable variable `bar` initialization is not allowed in `static this`
+fail_compilation/fail4923.d(5):        Use `shared static this` instead.
+fail_compilation/fail4923.d(6): Deprecation: const variable `baz` initialization is not allowed in `static this`
+fail_compilation/fail4923.d(6):        Use `shared static this` instead.
 ---
 */
 #line 1
 immutable int bar;
+const int baz; // https://issues.dlang.org/show_bug.cgi?id=24056
 static this()
 {
     bar = 42;
+    baz = 43;
 }
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail50.d b/gcc/testsuite/gdc.test/fail_compilation/fail50.d
index 36bf382af88..c6aa178bdaa 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail50.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail50.d
@@ -1,7 +1,7 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/fail50.d(12): Error: need `this` for address of `a`
+fail_compilation/fail50.d(12): Error: taking the address of non-static variable `a` requires an instance of `Marko`
 fail_compilation/fail50.d(12): Error: variable `a` cannot be read at compile time
 ---
 */
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail61.d b/gcc/testsuite/gdc.test/fail_compilation/fail61.d
index 1386bd664a3..a2f01d7e3ef 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail61.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail61.d
@@ -4,7 +4,7 @@ TEST_OUTPUT:
 fail_compilation/fail61.d(22): Error: no property `B` for type `fail61.A.B`
 fail_compilation/fail61.d(23): Error: no property `B` for type `fail61.A.B`
 fail_compilation/fail61.d(32): Error: no property `A2` for type `fail61.B2`
-fail_compilation/fail61.d(41): Error: need `this` for `foo` of type `void()`
+fail_compilation/fail61.d(41): Error: calling non-static function `foo` requires an instance of type `B3`
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail66.d b/gcc/testsuite/gdc.test/fail_compilation/fail66.d
index 5820ca519b0..825074ee897 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail66.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail66.d
@@ -53,7 +53,7 @@ fail_compilation/fail66.d(59): Error: cannot modify `const` expression `x`
 class C4
 {
     static const int x;
-    static this() { x = 5; }
+    shared static this() { x = 5; }
     void foo()
     {
         x = 4;
@@ -67,7 +67,7 @@ fail_compilation/fail66.d(73): Error: cannot modify `const` expression `z5`
 ---
 */
 const int z5;
-static this() { z5 = 3; }
+shared static this() { z5 = 3; }
 void test5()
 {
     z5 = 4;
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail7851.d b/gcc/testsuite/gdc.test/fail_compilation/fail7851.d
index 399192d750f..acc49f144c3 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail7851.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail7851.d
@@ -2,9 +2,9 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/fail7851.d(38): Error: need `this` for `__mem_field_0` of type `int`
-fail_compilation/fail7851.d(38): Error: need `this` for `__mem_field_1` of type `long`
-fail_compilation/fail7851.d(38): Error: need `this` for `__mem_field_2` of type `float`
+fail_compilation/fail7851.d(38): Error: accessing non-static variable `__mem_field_0` requires an instance of `Tuple`
+fail_compilation/fail7851.d(38): Error: accessing non-static variable `__mem_field_1` requires an instance of `Tuple`
+fail_compilation/fail7851.d(38): Error: accessing non-static variable `__mem_field_2` requires an instance of `Tuple`
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail9613.d b/gcc/testsuite/gdc.test/fail_compilation/fail9613.d
index 31ca808181a..d88cd2ffb96 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail9613.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail9613.d
@@ -2,7 +2,7 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/fail9613.d(12): Error: `(arguments)` expected following `const(byte)`
+fail_compilation/fail9613.d(12): Error: `(arguments)` expected following `const(byte)`, not `.`
 fail_compilation/fail9613.d(12): Error: semicolon expected following auto declaration, not `.`
 ---
 */
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail_scope.d b/gcc/testsuite/gdc.test/fail_compilation/fail_scope.d
index f2095921968..8508b27d164 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/fail_scope.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail_scope.d
@@ -1,5 +1,5 @@
 /*
-REQUIRED_ARGS:
+REQUIRED_ARGS: -wo
 TEST_OUTPUT:
 ---
 fail_compilation/fail_scope.d(30): Deprecation: scope parameter `da` may not be returned
@@ -16,7 +16,7 @@ fail_compilation/fail_scope.d(82): Error: returning `& string` escapes a referen
 fail_compilation/fail_scope.d(92): Error: returning `cast(int[])a` escapes a reference to local variable `a`
 fail_compilation/fail_scope.d(100): Error: returning `cast(int[])a` escapes a reference to local variable `a`
 fail_compilation/fail_scope.d(108): Error: escaping reference to outer local variable `x`
-fail_compilation/fail_scope.d(127): Deprecation: returning `s.bar()` escapes a reference to local variable `s`
+fail_compilation/fail_scope.d(127): Warning: returning `s.bar()` escapes a reference to local variable `s`
 fail_compilation/fail_scope.d(137): Error: returning `foo16226(i)` escapes a reference to local variable `i`
 ---
 //fail_compilation/fail_scope.d(35): Error: scope variable `da` may not be returned
diff --git a/gcc/testsuite/gdc.test/fail_compilation/failcontracts.d b/gcc/testsuite/gdc.test/fail_compilation/failcontracts.d
index 9ba29700020..51275d0140e 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/failcontracts.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/failcontracts.d
@@ -1,15 +1,14 @@
 /* TEST_OUTPUT:
 ---
-fail_compilation/failcontracts.d(18): Error: missing `{ ... }` for function literal
-fail_compilation/failcontracts.d(18): Error: semicolon expected following auto declaration, not `bode`
-fail_compilation/failcontracts.d(19): Error: function declaration without return type. (Note that constructors are always named `this`)
-fail_compilation/failcontracts.d(19): Error: no identifier for declarator `test1()`
+fail_compilation/failcontracts.d(17): Error: missing `{ ... }` for function literal
+fail_compilation/failcontracts.d(17): Error: semicolon expected following auto declaration, not `bode`
+fail_compilation/failcontracts.d(18): Error: function declaration without return type. (Note that constructors are always named `this`)
+fail_compilation/failcontracts.d(18): Error: no identifier for declarator `test1()`
+fail_compilation/failcontracts.d(18): Error: semicolon expected following function declaration, not `bode`
 fail_compilation/failcontracts.d(19): Error: semicolon expected following function declaration, not `bode`
-fail_compilation/failcontracts.d(20): Error: semicolon expected following function declaration, not `bode`
-fail_compilation/failcontracts.d(22): Error: unexpected `(` in declarator
-fail_compilation/failcontracts.d(22): Error: found `T` when expecting `)`
-fail_compilation/failcontracts.d(22): Error: enum declaration is invalid
-fail_compilation/failcontracts.d(22): Error: found `)` instead of statement
+fail_compilation/failcontracts.d(21): Error: unexpected `(` in declarator
+fail_compilation/failcontracts.d(21): Error: found `T` when expecting `)`
+fail_compilation/failcontracts.d(21): Error: expected `{`, not `;` for enum declaration
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/fail_compilation/ice15332.d b/gcc/testsuite/gdc.test/fail_compilation/ice15332.d
index dbedc73a6e4..67895835823 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/ice15332.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/ice15332.d
@@ -1,8 +1,8 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/ice15332.d(16): Error: need `this` for `fun` of type `int()`
-fail_compilation/ice15332.d(17): Error: need `this` for `var` of type `int`
+fail_compilation/ice15332.d(16): Error: calling non-static function `fun` requires an instance of type `C`
+fail_compilation/ice15332.d(17): Error: accessing non-static variable `var` requires an instance of `C`
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/fail_compilation/ice15922.d b/gcc/testsuite/gdc.test/fail_compilation/ice15922.d
index d98404ca34a..624124b187a 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/ice15922.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/ice15922.d
@@ -4,7 +4,7 @@ TEST_OUTPUT:
 fail_compilation/ice15922.d(23): Error: function `ice15922.ValidSparseDataStore!int.ValidSparseDataStore.correctedInsert!false.correctedInsert` has no `return` statement, but is expected to return a value of type `int`
 fail_compilation/ice15922.d(21): Error: template instance `ice15922.ValidSparseDataStore!int.ValidSparseDataStore.correctedInsert!false` error instantiating
 fail_compilation/ice15922.d(26):        instantiated from here: `ValidSparseDataStore!int`
-fail_compilation/ice15922.d(14): Error: need `this` for `insert` of type `pure nothrow @nogc @safe int()`
+fail_compilation/ice15922.d(14): Error: calling non-static function `insert` requires an instance of type `ValidSparseDataStore`
 fail_compilation/ice15922.d(26): Error: template instance `ice15922.StorageAttributes!(ValidSparseDataStore!int)` error instantiating
 ---
 */
diff --git a/gcc/testsuite/gdc.test/fail_compilation/ice20056.d b/gcc/testsuite/gdc.test/fail_compilation/ice20056.d
index 1b991cae66d..519ada11eb7 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/ice20056.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/ice20056.d
@@ -1,7 +1,7 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/ice20056.d(19): Error: need `this` for `iter` of type `void()`
+fail_compilation/ice20056.d(19): Error: calling non-static function `iter` requires an instance of type `RangeWrapper`
 ---
 */
 struct Def(alias fn)
diff --git a/gcc/testsuite/gdc.test/fail_compilation/ice7645.d b/gcc/testsuite/gdc.test/fail_compilation/ice7645.d
index 379ac67d0c5..3fd332c61b3 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/ice7645.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/ice7645.d
@@ -1,8 +1,8 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/ice7645.d(28): Error: need `this` for `t` of type `char`
-fail_compilation/ice7645.d(31): Error: need `this` for `fn` of type `pure nothrow @nogc @safe void()`
+fail_compilation/ice7645.d(28): Error: accessing non-static variable `t` requires an instance of `C2`
+fail_compilation/ice7645.d(31): Error: calling non-static function `fn` requires an instance of type `S2`
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/fail_compilation/ice9439.d b/gcc/testsuite/gdc.test/fail_compilation/ice9439.d
index 5b2a8b12031..9f08e404be5 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/ice9439.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/ice9439.d
@@ -1,7 +1,7 @@
 /*
 TEST_OUTPUT:
 ---
-fail_compilation/ice9439.d(12): Error: need `this` for `foo` of type `int()`
+fail_compilation/ice9439.d(12): Error: calling non-static function `foo` requires an instance of type `Derived`
 fail_compilation/ice9439.d(12):        while evaluating: `static assert(foo())`
 fail_compilation/ice9439.d(19): Error: template instance `ice9439.Base.boo!(foo)` error instantiating
 ---
diff --git a/gcc/testsuite/gdc.test/fail_compilation/misc_parser_err_cov1.d b/gcc/testsuite/gdc.test/fail_compilation/misc_parser_err_cov1.d
index a719b123a6a..57706b59e41 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/misc_parser_err_cov1.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/misc_parser_err_cov1.d
@@ -17,7 +17,7 @@ fail_compilation/misc_parser_err_cov1.d(38): Error: template argument expected f
 fail_compilation/misc_parser_err_cov1.d(38): Error: missing closing `)` after `if (parseShift!()`
 fail_compilation/misc_parser_err_cov1.d(38): Error: found `)` when expecting `(`
 fail_compilation/misc_parser_err_cov1.d(39): Error: missing closing `)` after `if (`
-fail_compilation/misc_parser_err_cov1.d(39): Error: identifier expected following `(type)`.
+fail_compilation/misc_parser_err_cov1.d(39): Error: identifier expected following `immutable(int).`, not `+`
 fail_compilation/misc_parser_err_cov1.d(39): Error: expression expected, not `;`
 fail_compilation/misc_parser_err_cov1.d(40): Error: semicolon expected following auto declaration, not `auto`
 fail_compilation/misc_parser_err_cov1.d(40): Error: identifier or `new` expected following `.`, not `+`
diff --git a/gcc/testsuite/gdc.test/fail_compilation/mixintype2.d b/gcc/testsuite/gdc.test/fail_compilation/mixintype2.d
index b18627dd879..13cc827f09d 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/mixintype2.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/mixintype2.d
@@ -1,8 +1,11 @@
 
 /* TEST_OUTPUT:
 ---
-fail_compilation/mixintype2.d(10): Error: alias `mixintype2.Foo.T` recursive alias declaration
-fail_compilation/mixintype2.d(16): Error: `mixin(0)` does not give a valid type
+fail_compilation/mixintype2.d(13): Error: alias `mixintype2.Foo.T` recursive alias declaration
+fail_compilation/mixintype2.d(19): Error: `mixin(0)` does not give a valid type
+fail_compilation/mixintype2.d(20): Error: unexpected token `{` after type `int()`
+fail_compilation/mixintype2.d(20):        while parsing string mixin type `int() {}`
+fail_compilation/mixintype2.d(20): Error: `mixin(_error_)` does not give a valid type
 ---
 */
 
@@ -14,3 +17,4 @@ alias T2 = mixin("T1");
 void func (T2 p) {}
 
 enum mixin(0) a = 0;
+mixin("int() {}") f;
diff --git a/gcc/testsuite/gdc.test/fail_compilation/noreturn.d b/gcc/testsuite/gdc.test/fail_compilation/noreturn.d
index d47d44917ba..087b9e7c646 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/noreturn.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/noreturn.d
@@ -3,18 +3,18 @@ REQUIRED_ARGS: -w -o-
 
 TEST_OUTPUT:
 ---
-fail_compilation\noreturn.d(38): Error: `"Accessed expression of type `noreturn`"`
+fail_compilation\noreturn.d(38): Error: Accessed expression of type `noreturn`
 fail_compilation\noreturn.d(42):        called from here: `assign()`
-fail_compilation\noreturn.d(49): Error: `"Accessed expression of type `noreturn`"`
+fail_compilation\noreturn.d(49): Error: Accessed expression of type `noreturn`
 fail_compilation\noreturn.d(49):        called from here: `foo(n)`
 fail_compilation\noreturn.d(53):        called from here: `calling()`
-fail_compilation\noreturn.d(59): Error: `"Accessed expression of type `noreturn`"`
+fail_compilation\noreturn.d(59): Error: Accessed expression of type `noreturn`
 fail_compilation\noreturn.d(62):        called from here: `nested()`
-fail_compilation\noreturn.d(68): Error: `"Accessed expression of type `noreturn`"`
+fail_compilation\noreturn.d(68): Error: Accessed expression of type `noreturn`
 fail_compilation\noreturn.d(78):        called from here: `casting(0)`
-fail_compilation\noreturn.d(69): Error: `"Accessed expression of type `noreturn`"`
+fail_compilation\noreturn.d(69): Error: Accessed expression of type `noreturn`
 fail_compilation\noreturn.d(79):        called from here: `casting(1)`
-fail_compilation\noreturn.d(72): Error: `"Accessed expression of type `noreturn`"`
+fail_compilation\noreturn.d(72): Error: Accessed expression of type `noreturn`
 fail_compilation\noreturn.d(80):        called from here: `casting(2)`
 fail_compilation/noreturn.d(120): Error: uncaught CTFE exception `object.Exception("")`
 ---
@@ -125,7 +125,7 @@ https://issues.dlang.org/show_bug.cgi?id=23063
 
 TEST_OUTPUT:
 ---
-fail_compilation/noreturn.d(135): Error: `"Accessed expression of type `noreturn`"`
+fail_compilation/noreturn.d(135): Error: Accessed expression of type `noreturn`
 fail_compilation/noreturn.d(138):        called from here: `func()`
 ---
 */
diff --git a/gcc/testsuite/gdc.test/fail_compilation/noreturn2.d b/gcc/testsuite/gdc.test/fail_compilation/noreturn2.d
index 7bb2fa9ab48..66c1d5287f5 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/noreturn2.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/noreturn2.d
@@ -139,3 +139,16 @@ int throwInvalid(int i) nothrow
             UnkownException("")
     ;
 }
+
+/+
+https://issues.dlang.org/show_bug.cgi?id=24054
+TEST_OUTPUT:
+---
+fail_compilation/noreturn2.d(153): Error: cannot return from `noreturn` function
+fail_compilation/noreturn2.d(153):        Consider adding an endless loop, `assert(0)`, or another `noreturn` expression
+---
++/
+const(noreturn) f()
+{
+    return;
+}
diff --git a/gcc/testsuite/gdc.test/fail_compilation/systemvariables.d b/gcc/testsuite/gdc.test/fail_compilation/systemvariables.d
index 0079719e355..796eda60935 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/systemvariables.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/systemvariables.d
@@ -2,15 +2,24 @@
 REQUIRED_ARGS: -preview=systemVariables
 TEST_OUTPUT:
 ---
-fail_compilation/systemvariables.d(30): Error: cannot access `@system` variable `gInt` in @safe code
-fail_compilation/systemvariables.d(31): Error: cannot access `@system` variable `gInt` in @safe code
-fail_compilation/systemvariables.d(32): Error: cannot access `@system` variable `gArr` in @safe code
-fail_compilation/systemvariables.d(33): Error: cannot access `@system` variable `gArr` in @safe code
-fail_compilation/systemvariables.d(34): Error: cannot access `@system` variable `gInt` in @safe code
-fail_compilation/systemvariables.d(37): Error: cannot access `@system` variable `lSys` in @safe code
-fail_compilation/systemvariables.d(38): Error: cannot access `@system` variable `lSys` in @safe code
-fail_compilation/systemvariables.d(39): Error: cannot access `@system` variable `lSys` in @safe code
-fail_compilation/systemvariables.d(41): Error: cannot access `@system` variable `eInt` in @safe code
+fail_compilation/systemvariables.d(39): Error: cannot access `@system` variable `gInt` in @safe code
+fail_compilation/systemvariables.d(29):        `gInt` is declared here
+fail_compilation/systemvariables.d(40): Error: cannot access `@system` variable `gInt` in @safe code
+fail_compilation/systemvariables.d(29):        `gInt` is declared here
+fail_compilation/systemvariables.d(41): Error: cannot access `@system` variable `gArr` in @safe code
+fail_compilation/systemvariables.d(31):        `gArr` is declared here
+fail_compilation/systemvariables.d(42): Error: cannot access `@system` variable `gArr` in @safe code
+fail_compilation/systemvariables.d(31):        `gArr` is declared here
+fail_compilation/systemvariables.d(43): Error: cannot access `@system` variable `gInt` in @safe code
+fail_compilation/systemvariables.d(29):        `gInt` is declared here
+fail_compilation/systemvariables.d(46): Error: cannot access `@system` variable `lSys` in @safe code
+fail_compilation/systemvariables.d(45):        `lSys` is declared here
+fail_compilation/systemvariables.d(47): Error: cannot access `@system` variable `lSys` in @safe code
+fail_compilation/systemvariables.d(45):        `lSys` is declared here
+fail_compilation/systemvariables.d(48): Error: cannot access `@system` variable `lSys` in @safe code
+fail_compilation/systemvariables.d(45):        `lSys` is declared here
+fail_compilation/systemvariables.d(50): Error: cannot access `@system` variable `eInt` in @safe code
+fail_compilation/systemvariables.d(30):        `eInt` is declared here
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/fail_compilation/test13536.d b/gcc/testsuite/gdc.test/fail_compilation/test13536.d
index f4e2cac93cc..4a4bb2672be 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/test13536.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/test13536.d
@@ -1,8 +1,8 @@
-/*
+/* REQUIRED_ARGS: -wo
 TEST_OUTPUT:
 ---
 fail_compilation/test13536.d(23): Error: field `U.sysDg` cannot access pointers in `@safe` code that overlap other fields
-fail_compilation/test13536.d(23): Deprecation: address of variable `s` assigned to `u` with longer lifetime
+fail_compilation/test13536.d(23): Warning: address of variable `s` assigned to `u` with longer lifetime
 fail_compilation/test13536.d(24): Error: field `U.safeDg` cannot access pointers in `@safe` code that overlap other fields
 ---
 */
diff --git a/gcc/testsuite/gdc.test/fail_compilation/test16365.d b/gcc/testsuite/gdc.test/fail_compilation/test16365.d
index c9879699875..4d49365659c 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/test16365.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/test16365.d
@@ -1,9 +1,9 @@
-/*
+/* REQUIRED_ARGS: -wo
 TEST_OUTPUT:
 ---
 fail_compilation/test16365.d(21): Error: `this` reference necessary to take address of member `f1` in `@safe` function `main`
 fail_compilation/test16365.d(23): Error: cannot implicitly convert expression `&f2` of type `void delegate() pure nothrow @nogc @safe` to `void function() @safe`
-fail_compilation/test16365.d(27): Deprecation: address of variable `s` assigned to `dg` with longer lifetime
+fail_compilation/test16365.d(27): Warning: address of variable `s` assigned to `dg` with longer lifetime
 fail_compilation/test16365.d(28): Error: `dg.funcptr` cannot be used in `@safe` code
 ---
 */
diff --git a/gcc/testsuite/gdc.test/fail_compilation/test21008.d b/gcc/testsuite/gdc.test/fail_compilation/test21008.d
index 7d5bb375c10..99491078476 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/test21008.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/test21008.d
@@ -2,8 +2,8 @@
 TEST_OUTPUT:
 ---
 fail_compilation/test21008.d(110): Error: function `test21008.C.after` circular reference to class `C`
-fail_compilation/test21008.d(117): Error: need `this` for `toString` of type `string()`
-fail_compilation/test21008.d(117): Error: need `this` for `toHash` of type `nothrow @trusted $?:32=uint|64=ulong$()`
+fail_compilation/test21008.d(117): Error: calling non-static function `toString` requires an instance of type `Object`
+fail_compilation/test21008.d(117): Error: calling non-static function `toHash` requires an instance of type `Object`
 fail_compilation/test21008.d(117): Error: function `object.Object.opCmp(Object o)` is not callable using argument types `()`
 fail_compilation/test21008.d(117):        too few arguments, expected 1, got 0
 fail_compilation/test21008.d(117): Error: function `object.Object.opEquals(Object o)` is not callable using argument types `()`
diff --git a/gcc/testsuite/gdc.test/fail_compilation/test9701.d b/gcc/testsuite/gdc.test/fail_compilation/test9701.d
index a0310c413fb..67f38fcafbb 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/test9701.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/test9701.d
@@ -5,27 +5,27 @@ fail_compilation/test9701.d(38): Error: `@safe` is not a valid attribute for enu
 fail_compilation/test9701.d(39): Error: `@system` is not a valid attribute for enum members
 fail_compilation/test9701.d(40): Error: `@trusted` is not a valid attribute for enum members
 fail_compilation/test9701.d(41): Error: `@nogc` is not a valid attribute for enum members
-fail_compilation/test9701.d(42): Error: `pure` is not a valid attribute for enum members
-fail_compilation/test9701.d(43): Error: `shared` is not a valid attribute for enum members
-fail_compilation/test9701.d(44): Error: `inout` is not a valid attribute for enum members
-fail_compilation/test9701.d(45): Error: `immutable` is not a valid attribute for enum members
-fail_compilation/test9701.d(46): Error: `const` is not a valid attribute for enum members
-fail_compilation/test9701.d(47): Error: `synchronized` is not a valid attribute for enum members
-fail_compilation/test9701.d(48): Error: `scope` is not a valid attribute for enum members
-fail_compilation/test9701.d(49): Error: `auto` is not a valid attribute for enum members
-fail_compilation/test9701.d(50): Error: `ref` is not a valid attribute for enum members
-fail_compilation/test9701.d(51): Error: `__gshared` is not a valid attribute for enum members
-fail_compilation/test9701.d(52): Error: `final` is not a valid attribute for enum members
-fail_compilation/test9701.d(53): Error: `extern` is not a valid attribute for enum members
-fail_compilation/test9701.d(54): Error: `export` is not a valid attribute for enum members
-fail_compilation/test9701.d(55): Error: `nothrow` is not a valid attribute for enum members
-fail_compilation/test9701.d(56): Error: `public` is not a valid attribute for enum members
-fail_compilation/test9701.d(57): Error: `private` is not a valid attribute for enum members
-fail_compilation/test9701.d(58): Error: `package` is not a valid attribute for enum members
-fail_compilation/test9701.d(59): Error: `static` is not a valid attribute for enum members
-fail_compilation/test9701.d(60): Error: `static` is not a valid attribute for enum members
-fail_compilation/test9701.d(61): Error: `static` is not a valid attribute for enum members
-fail_compilation/test9701.d(62): Error: `static` is not a valid attribute for enum members
+fail_compilation/test9701.d(42): Error: found `pure` when expecting `identifier`
+fail_compilation/test9701.d(43): Error: found `shared` when expecting `identifier`
+fail_compilation/test9701.d(44): Error: found `inout` when expecting `identifier`
+fail_compilation/test9701.d(45): Error: found `immutable` when expecting `identifier`
+fail_compilation/test9701.d(46): Error: found `const` when expecting `identifier`
+fail_compilation/test9701.d(47): Error: found `synchronized` when expecting `identifier`
+fail_compilation/test9701.d(48): Error: found `scope` when expecting `identifier`
+fail_compilation/test9701.d(49): Error: found `auto` when expecting `identifier`
+fail_compilation/test9701.d(50): Error: found `ref` when expecting `identifier`
+fail_compilation/test9701.d(51): Error: found `__gshared` when expecting `identifier`
+fail_compilation/test9701.d(52): Error: found `final` when expecting `identifier`
+fail_compilation/test9701.d(53): Error: found `extern` when expecting `identifier`
+fail_compilation/test9701.d(54): Error: found `export` when expecting `identifier`
+fail_compilation/test9701.d(55): Error: found `nothrow` when expecting `identifier`
+fail_compilation/test9701.d(56): Error: found `public` when expecting `identifier`
+fail_compilation/test9701.d(57): Error: found `private` when expecting `identifier`
+fail_compilation/test9701.d(58): Error: found `package` when expecting `identifier`
+fail_compilation/test9701.d(59): Error: found `static` when expecting `identifier`
+fail_compilation/test9701.d(60): Error: found `static` when expecting `identifier`
+fail_compilation/test9701.d(61): Error: found `static` when expecting `identifier`
+fail_compilation/test9701.d(62): Error: found `static` when expecting `identifier`
 ---
 */
 
diff --git a/gcc/testsuite/gdc.test/runnable/aliasthis.d b/gcc/testsuite/gdc.test/runnable/aliasthis.d
index 50e5c4db64b..db5913c8389 100644
--- a/gcc/testsuite/gdc.test/runnable/aliasthis.d
+++ b/gcc/testsuite/gdc.test/runnable/aliasthis.d
@@ -1,16 +1,7 @@
 /*
 TEST_OUTPUT:
 ---
-runnable/aliasthis.d(103): Deprecation: alias this for classes/interfaces is deprecated
-runnable/aliasthis.d(291): Deprecation: alias this for classes/interfaces is deprecated
-runnable/aliasthis.d(292): Deprecation: alias this for classes/interfaces is deprecated
-runnable/aliasthis.d(294): Deprecation: alias this for classes/interfaces is deprecated
-runnable/aliasthis.d(465): Deprecation: alias this for classes/interfaces is deprecated
-runnable/aliasthis.d(466): Deprecation: alias this for classes/interfaces is deprecated
-runnable/aliasthis.d(477): Deprecation: alias this for classes/interfaces is deprecated
-runnable/aliasthis.d(1013): Deprecation: alias this for classes/interfaces is deprecated
 false
-runnable/aliasthis.d(2100): Deprecation: alias this for classes/interfaces is deprecated
 [] = int
 [] = string
 [0] = int
@@ -19,7 +10,6 @@ runnable/aliasthis.d(2100): Deprecation: alias this for classes/interfaces is de
 [] = int
 [1] = string
 [0] = int
-runnable/aliasthis.d(741): Deprecation: alias this for classes/interfaces is deprecated
 ---
 
 RUN_OUTPUT:
diff --git a/gcc/testsuite/gdc.test/runnable/complex.d b/gcc/testsuite/gdc.test/runnable/complex.d
index 50e793e21e6..3a7291d18bf 100644
--- a/gcc/testsuite/gdc.test/runnable/complex.d
+++ b/gcc/testsuite/gdc.test/runnable/complex.d
@@ -243,11 +243,11 @@ void test12()
 {
     real x = 3;
     creal a = (2 + 4i) % 3;
-    printf("%Lg %Lgi\n", a.re, a.im);
+    //printf("%Lg %Lgi\n", a.re, a.im);
     assert(a == 2 + 1i);
 
     creal b = (2 + 4i) % x;
-    printf("%Lg %Lgi\n", b.re, b.im);
+    //printf("%Lg %Lgi\n", b.re, b.im);
     assert(b == a);
 }
 
@@ -257,7 +257,7 @@ void test13()
 {
         ireal a = 5i;
         ireal b = a % 2;
-        printf("%Lg %Lgi\n", b.re, b.im);
+        //printf("%Lg %Lgi\n", b.re, b.im);
         assert(b == 1i);
 }
 
@@ -530,9 +530,9 @@ void test22()
 {
     static creal[] params = [1+0i, 3+0i, 5+0i];
 
-    printf("params[0] = %Lf + %Lfi\n", params[0].re, params[0].im);
-    printf("params[1] = %Lf + %Lfi\n", params[1].re, params[1].im);
-    printf("params[2] = %Lf + %Lfi\n", params[2].re, params[2].im);
+    //printf("params[0] = %Lf + %Lfi\n", params[0].re, params[0].im);
+    //printf("params[1] = %Lf + %Lfi\n", params[1].re, params[1].im);
+    //printf("params[2] = %Lf + %Lfi\n", params[2].re, params[2].im);
 
     creal[] sums = new creal[3];
     sums[] = 0+0i;
@@ -603,19 +603,19 @@ float func_24_4(float f, double d)
 void test24()
 {
     ifloat f = func_24_1(10i, 8);
-    printf("%fi\n", f);
+    //printf("%fi\n", f);
 //    assert(f == 1.25i);
 
     f = func_24_2(10i, 8);
-    printf("%fi\n", f);
+    //printf("%fi\n", f);
     assert(f == 1.25i);
 
     float g = func_24_3(10, 8);
-    printf("%f\n", g);
+    //printf("%f\n", g);
 //    assert(g == 1.25);
 
     g = func_24_4(10, 8);
-    printf("%f\n", g);
+    //printf("%f\n", g);
     assert(g == 1.25);
 }
 
@@ -647,9 +647,9 @@ void test26()
   foreach( cdouble z; A )
   {
     s = toString26(z);
-    printf("%.*s  ", cast(int)s.length, s.ptr);
+    //printf("%.*s  ", cast(int)s.length, s.ptr);
   }
-  printf("\n");
+  //printf("\n");
 
   for(int ii=0; ii<A.length; ii++ )
     A[ii] += -1i*A[ii];
@@ -661,9 +661,9 @@ void test26()
   foreach( cdouble z; A )
   {
     s = toString26(z);
-    printf("%.*s  ", cast(int)s.length, s.ptr);
+    //printf("%.*s  ", cast(int)s.length, s.ptr);
   }
-  printf("\n");
+  //printf("\n");
 }
 
 /*************************************/
@@ -698,19 +698,19 @@ void test28()
 void test29()
 {
     ireal a = 6.5i % 3i;
-    printf("%Lfi %Lfi\n", a, a - .5i);
+    //printf("%Lfi %Lfi\n", a, a - .5i);
     assert(a == .5i);
 
     a = 6.5i % 3;
-    printf("%Lfi %Lfi\n", a, a - .5i);
+    //printf("%Lfi %Lfi\n", a, a - .5i);
     assert(a == .5i);
 
     real b = 6.5 % 3i;
-    printf("%Lf %Lf\n", b, b - .5);
+    //printf("%Lf %Lf\n", b, b - .5);
     assert(b == .5);
 
     b = 6.5 % 3;
-    printf("%Lf %Lf\n", b, b - .5);
+    //printf("%Lf %Lf\n", b, b - .5);
     assert(b == .5);
 }
 
@@ -720,17 +720,17 @@ void test30()
 {
     cfloat f = 1+0i;
     f %= 2fi;
-    printf("%f + %fi\n", f.re, f.im);
+    //printf("%f + %fi\n", f.re, f.im);
     assert(f == 1 + 0i);
 
     cdouble d = 1+0i;
     d %= 2i;
-    printf("%f + %fi\n", d.re, d.im);
+    //printf("%f + %fi\n", d.re, d.im);
     assert(d == 1 + 0i);
 
     creal r = 1+0i;
     r %= 2i;
-    printf("%Lf + %Lfi\n", r.re, r.im);
+    //printf("%Lf + %Lfi\n", r.re, r.im);
     assert(r == 1 + 0i);
 }
 
@@ -740,17 +740,17 @@ void test31()
 {
     cfloat f = 1+0i;
     f %= 2i;
-    printf("%f + %fi\n", f.re, f.im);
+    //printf("%f + %fi\n", f.re, f.im);
     assert(f == 1);
 
     cdouble d = 1+0i;
     d = d % 2i;
-    printf("%f + %fi\n", d.re, d.im);
+    //printf("%f + %fi\n", d.re, d.im);
     assert(d == 1);
 
     creal r = 1+0i;
     r = r % 2i;
-    printf("%Lf + %Lfi\n", r.re, r.im);
+    //printf("%Lf + %Lfi\n", r.re, r.im);
     assert(r == 1);
 }
 
@@ -770,7 +770,7 @@ void assertEqual(real* a, real* b, string file = __FILE__, size_t line = __LINE_
     {
         if (x[i] != y[i])
         {
-            printf("%02zd: %02x %02x\n", i, x[i], y[i]);
+            //printf("%02zd: %02x %02x\n", i, x[i], y[i]);
             import core.exception;
             throw new AssertError(file, line);
         }
@@ -856,7 +856,7 @@ void test35()
 void test36()
 {
     ireal imag = 2.5i;
-    printf ("test of imag*imag = %Lf\n",imag*imag);
+    //printf ("test of imag*imag = %Lf\n",imag*imag);
     assert(imag * imag == -6.25);
 }
 
@@ -885,7 +885,7 @@ void test39()
     creal z = 1 + 2.5i;
     real e = z.im;
 
-    printf ("e = %Lf\n", e);
+    //printf ("e = %Lf\n", e);
     assert(e == 2.5);
 }
 
@@ -942,7 +942,7 @@ void test44()
 {
     ifloat f = 1.0fi;
 //    f *= 2.0fi; // illegal but compiles
-    printf("%g\n", f);
+    //printf("%g\n", f);
 //    assert(f == 0i);
 }
 
diff --git a/gcc/testsuite/gdc.test/runnable/interpret.d b/gcc/testsuite/gdc.test/runnable/interpret.d
index f9972f235e2..ee324d71f80 100644
--- a/gcc/testsuite/gdc.test/runnable/interpret.d
+++ b/gcc/testsuite/gdc.test/runnable/interpret.d
@@ -4,7 +4,6 @@ TEST_OUTPUT:
 true
 g
 &Test109S(&Test109S(<recursion>))
-runnable/interpret.d(3742): Deprecation: alias this for classes/interfaces is deprecated
 tfoo
 tfoo
 Crash!
@@ -2197,7 +2196,7 @@ struct Q
     Q opOpAssign(string op)(int w) if (op == "-")
     {
         x -= w;
-        version(D_Version2) { mixin("return this;"); } else { mixin("return *this;"); }
+        return this;
     }
     int boo()  { return 4; }
     int coo()  { return x; }
@@ -2427,7 +2426,7 @@ static assert(bug1605() == 27);
 
 int bug2564()
 {
-    version(D_Version2) { mixin("enum int Q = 0;"); }else {mixin("int Q = 0;"); }
+    enum int Q = 0;
     string [2] s = ["a", "b"];
     assert(s[Q].dup == "a");
     return 0;
@@ -2646,8 +2645,6 @@ static assert(lazyTest2(17) == 18);
 
 /************************************************/
 
-version(D_Version2)
-{
 // https://issues.dlang.org/show_bug.cgi?id=4020
 // https://issues.dlang.org/show_bug.cgi?id=4027
 // D2 only
@@ -2677,7 +2674,6 @@ static if (is(typeof((){ static const s = bug4027("aaa")(); }()))) {
     static assert(bug4027("aaa")() == "aaa");
     static assert(bug4027("bbb")() == "bbb");
 }
-}
 
 // ---
 
diff --git a/gcc/testsuite/gdc.test/runnable/template9.d b/gcc/testsuite/gdc.test/runnable/template9.d
index dbad3f1daec..fa70b81c78b 100644
--- a/gcc/testsuite/gdc.test/runnable/template9.d
+++ b/gcc/testsuite/gdc.test/runnable/template9.d
@@ -1991,7 +1991,7 @@ void test8976()
 // https://issues.dlang.org/show_bug.cgi?id=8940
 
 const int n8940; // or `immutable`
-static this() { n8940 = 3; }
+shared static this() { n8940 = 3; }
 
 void f8940(T)(ref int val)
 {
diff --git a/gcc/testsuite/gdc.test/runnable/test17684.d b/gcc/testsuite/gdc.test/runnable/test17684.d
index e10265558e8..efdce0847ba 100644
--- a/gcc/testsuite/gdc.test/runnable/test17684.d
+++ b/gcc/testsuite/gdc.test/runnable/test17684.d
@@ -1,13 +1,3 @@
-/*
-TEST_OUTPUT:
----
-runnable/test17684.d(37): Deprecation: alias this for classes/interfaces is deprecated
-runnable/test17684.d(54): Deprecation: alias this for classes/interfaces is deprecated
-runnable/test17684.d(54): Deprecation: alias this for classes/interfaces is deprecated
-runnable/test17684.d(37): Deprecation: alias this for classes/interfaces is deprecated
----
-*/
-
 struct StructField(T)
 {
     static T Field;
diff --git a/gcc/testsuite/gdc.test/runnable/test19782.d b/gcc/testsuite/gdc.test/runnable/test19782.d
index 61a168bf918..a24d84173ec 100644
--- a/gcc/testsuite/gdc.test/runnable/test19782.d
+++ b/gcc/testsuite/gdc.test/runnable/test19782.d
@@ -1,12 +1,4 @@
 // https://issues.dlang.org/show_bug.cgi?id=19782
-
-/*
-TEST_OUTPUT:
----
-runnable/test19782.d(17): Deprecation: alias this for classes/interfaces is deprecated
----
-*/
-
 class Inner
 {
     int a;
diff --git a/gcc/testsuite/gdc.test/runnable/test20.d b/gcc/testsuite/gdc.test/runnable/test20.d
index 5d47b06a7fe..5036ef2a806 100644
--- a/gcc/testsuite/gdc.test/runnable/test20.d
+++ b/gcc/testsuite/gdc.test/runnable/test20.d
@@ -1104,7 +1104,7 @@ class C60
     {
     }
 
-    static this()
+    shared static this()
     {
         x = 5;
     }
@@ -1117,7 +1117,7 @@ class C60
 
 const int z60;
 
-static this()
+shared static this()
 {
     z60 = 3;
 }
diff --git a/gcc/testsuite/gdc.test/runnable/test21039.d b/gcc/testsuite/gdc.test/runnable/test21039.d
index f32267ab59e..c58600f8da0 100644
--- a/gcc/testsuite/gdc.test/runnable/test21039.d
+++ b/gcc/testsuite/gdc.test/runnable/test21039.d
@@ -1,12 +1,5 @@
 // https://issues.dlang.org/show_bug.cgi?id=21039
 
-/*
-TEST_OUTPUT:
----
-runnable/test21039.d(14): Deprecation: alias this for classes/interfaces is deprecated
----
-*/
-
 class Inner {}
 
 class Outer {
diff --git a/gcc/testsuite/gdc.test/runnable/test23234.d b/gcc/testsuite/gdc.test/runnable/test23234.d
index f97486404b3..7872aa76dfe 100644
--- a/gcc/testsuite/gdc.test/runnable/test23234.d
+++ b/gcc/testsuite/gdc.test/runnable/test23234.d
@@ -1,12 +1,5 @@
 // https://issues.dlang.org/show_bug.cgi?id=23234
 
-/*
-TEST_OUTPUT:
----
-runnable/test23234.d(17): Deprecation: alias this for classes/interfaces is deprecated
----
-*/
-
 class Bar
 {
 }
diff --git a/gcc/testsuite/gdc.test/runnable/test3449.d b/gcc/testsuite/gdc.test/runnable/test3449.d
index 8d389188463..c06674a0a37 100644
--- a/gcc/testsuite/gdc.test/runnable/test3449.d
+++ b/gcc/testsuite/gdc.test/runnable/test3449.d
@@ -12,11 +12,11 @@ immutable int ig1;
 static this()
 {
     mg1 = 10;
-    cg1 = 10;
 }
 
 shared static this()
 {
+    cg1 = 10;
     ig1 = 10;
 }
 static assert(!__traits(compiles, { static assert(mg1 == 0); }));
diff --git a/gcc/testsuite/gdc.test/runnable/test42.d b/gcc/testsuite/gdc.test/runnable/test42.d
index 436f707b620..d89c152aa48 100644
--- a/gcc/testsuite/gdc.test/runnable/test42.d
+++ b/gcc/testsuite/gdc.test/runnable/test42.d
@@ -6167,7 +6167,7 @@ void test5332()
 
 const int x11472 = void;
 
-static this() { x11472 = 10; }
+shared static this() { x11472 = 10; }
 
 void test11472()
 {
diff --git a/gcc/testsuite/gdc.test/runnable/testaliascast.d b/gcc/testsuite/gdc.test/runnable/testaliascast.d
index ed5091dff01..c55f8203499 100644
--- a/gcc/testsuite/gdc.test/runnable/testaliascast.d
+++ b/gcc/testsuite/gdc.test/runnable/testaliascast.d
@@ -1,13 +1,5 @@
 // https://issues.dlang.org/show_bug.cgi?id=11294
 
-/*
-TEST_OUTPUT:
----
-runnable/testaliascast.d(29): Deprecation: alias this for classes/interfaces is deprecated
-runnable/testaliascast.d(58): Deprecation: alias this for classes/interfaces is deprecated
----
-*/
-
 string result;
 
 extern(C) void rt_finalize(void *ptr, bool det=true);
diff --git a/gcc/testsuite/gdc.test/runnable/testassign.d b/gcc/testsuite/gdc.test/runnable/testassign.d
index 79a4c57cf3b..c2b8a513ee1 100644
--- a/gcc/testsuite/gdc.test/runnable/testassign.d
+++ b/gcc/testsuite/gdc.test/runnable/testassign.d
@@ -2,8 +2,6 @@
 REQUIRED_ARGS: -preview=rvaluerefparam
 TEST_OUTPUT:
 ---
-runnable/testassign.d(802): Deprecation: alias this for classes/interfaces is deprecated
-runnable/testassign.d(808): Deprecation: alias this for classes/interfaces is deprecated
 \	S1	S2a	S2b	S3a	S3b	S4a	S4b
 -	true	true	true	true	true	true	true
 Xa	true	true	true	true	true	true	true
@@ -363,7 +361,7 @@ struct CtorTest6174(Data)
 
 const char gc6174;
 const char[1] ga6174;
-static this()
+shared static this()
 {
     gc6174 = 'a';    // OK
     ga6174[0] = 'a'; // line 5, Err
@@ -728,7 +726,7 @@ struct Foo8783
 
 const Foo8783[1] foos8783;
 
-static this()
+shared static this()
 {
     foreach (i; 0 .. foos8783.length)
         foos8783[i].bar[i] = 1; // OK
diff --git a/gcc/testsuite/gdc.test/runnable/testconst.d b/gcc/testsuite/gdc.test/runnable/testconst.d
index 17e3236f80f..43f986de9db 100644
--- a/gcc/testsuite/gdc.test/runnable/testconst.d
+++ b/gcc/testsuite/gdc.test/runnable/testconst.d
@@ -551,7 +551,7 @@ void test38()
 static const int x39;
 const int y39;
 
-static this()
+shared static this()
 {
     x39 = 3;
     y39 = 4;
@@ -613,7 +613,7 @@ class C42
     static const int d;
     static const int e = ctfe() + 2;
 
-    static this()
+    shared static this()
     {
         d = 4;
     }
@@ -1302,7 +1302,7 @@ void test78()
 
 const bool[string] stopWords79;
 
-static this()
+shared static this()
 {
     stopWords79 = [ "a"[]:1 ];
 }
diff --git a/gcc/testsuite/gdc.test/runnable/testswitch.d b/gcc/testsuite/gdc.test/runnable/testswitch.d
index c7b9378f842..47446972b7f 100644
--- a/gcc/testsuite/gdc.test/runnable/testswitch.d
+++ b/gcc/testsuite/gdc.test/runnable/testswitch.d
@@ -353,15 +353,11 @@ int foo15(int i)
     return y;
 }
 
-static this()
-{
-    X15 = 4;
-    Z15 = 5;
-}
-
 shared static this()
 {
+    X15 = 4;
     Y15 = 4;
+    Z15 = 5;
 }
 
 void test15()
diff --git a/gcc/testsuite/gdc.test/runnable/traits_getPointerBitmap.d b/gcc/testsuite/gdc.test/runnable/traits_getPointerBitmap.d
index ffa0b803ade..8996c9ebb8f 100644
--- a/gcc/testsuite/gdc.test/runnable/traits_getPointerBitmap.d
+++ b/gcc/testsuite/gdc.test/runnable/traits_getPointerBitmap.d
@@ -1,3 +1,4 @@
+
 module traits_getPointerBitmap;
 
 import core.stdc.stdio;
@@ -75,6 +76,19 @@ template pOff(T)
     enum pOff = T.p.offsetof / bytesPerPtr;
 }
 
+class C(T, aliasTo = void)
+{
+    static if(!is(aliasTo == void))
+    {
+        aliasTo a;
+        alias a this;
+    }
+
+    size_t x;
+    T t = void;
+    void* p;
+}
+
 ///////////////////////////////////////
 
 void _testType(T)(size_t[] expected)
@@ -104,6 +118,21 @@ void testType(T)(size_t[] expected)
     // prepend string
     sexp[0] = (expected[0] << tOff!(S!(T, string))) | (1 << pOff!(S!(T, string))) | 2; // arr ptr
     _testType!(S!(T, string))(sexp);
+
+    // generate bit pattern for C!T
+    C!T ct = null;
+    size_t mutexBit = (RTInfoMark__Monitor ? 2 : 0);
+    size_t ctpOff = ct.p.offsetof / bytesPerPtr;
+    size_t cttOff = ct.t.offsetof / bytesPerPtr;
+    sexp[0] = (expected[0] << cttOff) | (1 << ctpOff) | mutexBit;
+    _testType!(C!(T))(sexp);
+
+    C!(T, string) cts = null;
+    size_t ctspOff = cts.p.offsetof / bytesPerPtr;
+    size_t ctstOff = cts.t.offsetof / bytesPerPtr;
+    // generate bit pattern for C!T
+    sexp[0] = (expected[0] << ctstOff) | (1 << ctspOff) | mutexBit | 0b1000; // arr ptr
+    _testType!(C!(T, string))(sexp);
 }
 
 ///////////////////////////////////////
diff --git a/gcc/testsuite/gdc.test/runnable/xtest46.d b/gcc/testsuite/gdc.test/runnable/xtest46.d
index 972de900203..aeb2aab8336 100644
--- a/gcc/testsuite/gdc.test/runnable/xtest46.d
+++ b/gcc/testsuite/gdc.test/runnable/xtest46.d
@@ -2,14 +2,11 @@
 //
 /* TEST_OUTPUT:
 ---
-runnable/xtest46.d(165): Deprecation: alias this for classes/interfaces is deprecated
 Boo!double
 Boo!int
 true
 int
 !! immutable(int)[]
-runnable/xtest46.d(2932): Deprecation: alias this for classes/interfaces is deprecated
-runnable/xtest46.d(2964): Deprecation: alias this for classes/interfaces is deprecated
 int(int i, long j = 7L)
 long
 C10390(C10390(C10390(<recursion>)))
@@ -22,7 +19,6 @@ string[]
 double[]
 double[]
 {}
-runnable/xtest46.d(4670): Deprecation: alias this for classes/interfaces is deprecated
 AliasSeq!("m")
 true
 TFunction1: extern (C) void function()
diff --git a/gcc/testsuite/gdc.test/runnable/xtest46_gc.d b/gcc/testsuite/gdc.test/runnable/xtest46_gc.d
index aab6227230a..38c136d531c 100644
--- a/gcc/testsuite/gdc.test/runnable/xtest46_gc.d
+++ b/gcc/testsuite/gdc.test/runnable/xtest46_gc.d
@@ -3,14 +3,11 @@ REQUIRED_ARGS: -lowmem -Jrunnable -preview=rvaluerefparam
 EXTRA_FILES: xtest46.d
 TEST_OUTPUT:
 ---
-runnable/xtest46_gc.d-mixin-33(197): Deprecation: alias this for classes/interfaces is deprecated
 Boo!double
 Boo!int
 true
 int
 !! immutable(int)[]
-runnable/xtest46_gc.d-mixin-33(2964): Deprecation: alias this for classes/interfaces is deprecated
-runnable/xtest46_gc.d-mixin-33(2996): Deprecation: alias this for classes/interfaces is deprecated
 int(int i, long j = 7L)
 long
 C10390(C10390(<recursion>))
@@ -23,7 +20,6 @@ string[]
 double[]
 double[]
 {}
-runnable/xtest46_gc.d-mixin-33(4702): Deprecation: alias this for classes/interfaces is deprecated
 AliasSeq!("m")
 true
 TFunction1: extern (C) void function()
diff --git a/libphobos/libdruntime/MERGE b/libphobos/libdruntime/MERGE
index a02a8cbaba5..dc267787cab 100644
--- a/libphobos/libdruntime/MERGE
+++ b/libphobos/libdruntime/MERGE
@@ -1,4 +1,4 @@
-26f049fb26e755096dea3f1474decea7c0fef187
+4574d1728d1f7e52ff40e6733b8c39889d128349
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/libphobos/libdruntime/core/demangle.d b/libphobos/libdruntime/core/demangle.d
index f08e1f86444..f11315914d3 100644
--- a/libphobos/libdruntime/core/demangle.d
+++ b/libphobos/libdruntime/core/demangle.d
@@ -127,7 +127,7 @@ pure @safe:
 
     void putComma(size_t n)
     {
-        pragma(inline, false);
+        version (DigitalMars) pragma(inline, false);
         if (n)
             put(", ");
     }
@@ -2861,7 +2861,7 @@ private class OverflowException : Exception
 /// Ditto
 private noreturn error(string msg = "Invalid symbol") @trusted pure
 {
-    pragma(inline, false); // tame dmd inliner
+    version (DigitalMars) pragma(inline, false); // tame dmd inliner
 
     //throw new ParseException( msg );
     debug(info) printf( "error: %.*s\n", cast(int) msg.length, msg.ptr );
@@ -2872,7 +2872,7 @@ private noreturn error(string msg = "Invalid symbol") @trusted pure
 /// Ditto
 private noreturn overflow(string msg = "Buffer overflow") @trusted pure
 {
-    pragma(inline, false); // tame dmd inliner
+    version (DigitalMars) pragma(inline, false); // tame dmd inliner
 
     //throw new OverflowException( msg );
     debug(info) printf( "overflow: %.*s\n", cast(int) msg.length, msg.ptr );
@@ -2927,7 +2927,7 @@ private struct Buffer
     // move val to the end of the dst buffer
     char[] shift(scope const(char)[] val) return scope
     {
-        pragma(inline, false); // tame dmd inliner
+        version (DigitalMars) pragma(inline, false); // tame dmd inliner
 
         if (val.length)
         {
@@ -2949,7 +2949,7 @@ private struct Buffer
     // remove val from dst buffer
     void remove(scope const(char)[] val) scope
     {
-        pragma(inline, false); // tame dmd inliner
+        version (DigitalMars) pragma(inline, false); // tame dmd inliner
 
         if ( val.length )
         {
@@ -2965,7 +2965,7 @@ private struct Buffer
 
     char[] append(scope const(char)[] val) return scope
     {
-        pragma(inline, false); // tame dmd inliner
+        version (DigitalMars) pragma(inline, false); // tame dmd inliner
 
         if (val.length)
         {
diff --git a/libphobos/libdruntime/core/internal/array/appending.d b/libphobos/libdruntime/core/internal/array/appending.d
index b609167eefe..bb24813ae9e 100644
--- a/libphobos/libdruntime/core/internal/array/appending.d
+++ b/libphobos/libdruntime/core/internal/array/appending.d
@@ -35,7 +35,7 @@ template _d_arrayappendcTXImpl(Tarr : T[], T)
     ref Tarr _d_arrayappendcTX(return ref scope Tarr px, size_t n) @trusted pure nothrow
     {
         // needed for CTFE: https://github.com/dlang/druntime/pull/3870#issuecomment-1178800718
-        pragma(inline, false);
+        version (DigitalMars) pragma(inline, false);
         version (D_TypeInfo)
         {
             auto ti = typeid(Tarr);
@@ -70,7 +70,7 @@ template _d_arrayappendcTXImpl(Tarr : T[], T)
 /// Implementation of `_d_arrayappendT`
 ref Tarr _d_arrayappendT(Tarr : T[], T)(return ref scope Tarr x, scope Tarr y) @trusted
 {
-    pragma(inline, false);
+    version (DigitalMars) pragma(inline, false);
 
     import core.stdc.string : memcpy;
     import core.internal.traits : hasElaborateCopyConstructor, Unqual;
diff --git a/libphobos/libdruntime/core/internal/array/capacity.d b/libphobos/libdruntime/core/internal/array/capacity.d
index 254e9501f63..10ce2c65c95 100644
--- a/libphobos/libdruntime/core/internal/array/capacity.d
+++ b/libphobos/libdruntime/core/internal/array/capacity.d
@@ -36,7 +36,7 @@ template _d_arraysetlengthTImpl(Tarr : T[], T)
      */
     size_t _d_arraysetlengthT(return scope ref Tarr arr, size_t newlength) @trusted pure nothrow
     {
-        pragma(inline, false);
+        version (DigitalMars) pragma(inline, false);
         version (D_TypeInfo)
         {
             auto ti = typeid(Tarr);
diff --git a/libphobos/libdruntime/core/internal/array/construction.d b/libphobos/libdruntime/core/internal/array/construction.d
index ae71f513129..25083597761 100644
--- a/libphobos/libdruntime/core/internal/array/construction.d
+++ b/libphobos/libdruntime/core/internal/array/construction.d
@@ -36,7 +36,7 @@ import core.internal.traits : Unqual;
  */
 Tarr _d_arrayctor(Tarr : T[], T)(return scope Tarr to, scope Tarr from, char* makeWeaklyPure = null) @trusted
 {
-    pragma(inline, false);
+    version (DigitalMars) pragma(inline, false);
     import core.internal.traits : hasElaborateCopyConstructor;
     import core.lifetime : copyEmplace;
     import core.stdc.string : memcpy;
@@ -200,7 +200,7 @@ Tarr _d_arrayctor(Tarr : T[], T)(return scope Tarr to, scope Tarr from, char* ma
  */
 void _d_arraysetctor(Tarr : T[], T)(scope Tarr p, scope ref T value) @trusted
 {
-    pragma(inline, false);
+    version (DigitalMars) pragma(inline, false);
     import core.lifetime : copyEmplace;
 
     size_t i;
diff --git a/libphobos/libdruntime/core/memory.d b/libphobos/libdruntime/core/memory.d
index 96c2af478d3..4f44b604c45 100644
--- a/libphobos/libdruntime/core/memory.d
+++ b/libphobos/libdruntime/core/memory.d
@@ -270,7 +270,7 @@ extern(C):
      * reentrant, and must be called once for every call to disable before
      * automatic collections are enabled.
      */
-    pragma(mangle, "gc_enable") static void enable() nothrow pure;
+    pragma(mangle, "gc_enable") static void enable() @safe nothrow pure;
 
 
     /**
@@ -280,7 +280,7 @@ extern(C):
      * such as during an out of memory condition.  This function is reentrant,
      * but enable must be called once for each call to disable.
      */
-    pragma(mangle, "gc_disable") static void disable() nothrow pure;
+    pragma(mangle, "gc_disable") static void disable() @safe nothrow pure;
 
 
     /**
@@ -290,14 +290,14 @@ extern(C):
      * and then to reclaim free space.  This action may need to suspend all
      * running threads for at least part of the collection process.
      */
-    pragma(mangle, "gc_collect") static void collect() nothrow pure;
+    pragma(mangle, "gc_collect") static void collect() @safe nothrow pure;
 
     /**
      * Indicates that the managed memory space be minimized by returning free
      * physical memory to the operating system.  The amount of free memory
      * returned depends on the allocator design and on program behavior.
      */
-    pragma(mangle, "gc_minimize") static void minimize() nothrow pure;
+    pragma(mangle, "gc_minimize") static void minimize() @safe nothrow pure;
 
 extern(D):
 
diff --git a/libphobos/libdruntime/core/sys/windows/basetsd.d b/libphobos/libdruntime/core/sys/windows/basetsd.d
index 3c5c35f6603..e70dbdc6c22 100644
--- a/libphobos/libdruntime/core/sys/windows/basetsd.d
+++ b/libphobos/libdruntime/core/sys/windows/basetsd.d
@@ -10,39 +10,10 @@
 module core.sys.windows.basetsd;
 version (Windows):
 
-/*  This template is used in these modules to declare constant pointer types,
- *  in order to support both D 1.x and 2.x.
- *  Since removed - now supporting only D2
- */
-/*template CPtr(T) {
-    version (D_Version2) {
-        // must use mixin so that it doesn't cause a syntax error under D1
-        mixin("alias const(T)* CPtr;");
-    } else {
-        alias T* CPtr;
-    }
-}*/
-
-/*  [CyberShadow VP 2011.12.22] typedef is now deprecated in D2.
- */
-template TypeDef(T) {
-    version (D_Version2) {
-        alias T TypeDef;
-    } else {
-        // must use mixin so that it doesn't cause a deprecation error under D2
-        mixin("typedef T TypeDef;");
-    }
-}
-
 // [SnakE 2009-02-23] Moved HANDLE definition here from winnt.d to avoid
 // 'forwatd template reference' to CPtr from winnt.d caused by a circular
 // import.
-
-alias TypeDef!(void*) HANDLE;
-/+struct HANDLE {
-const(void)* h;
-    alias h this;
-}+/
+alias HANDLE = void*;
 
 package template DECLARE_HANDLE(string name, base = HANDLE) {
     mixin ("alias " ~ base.stringof ~ " " ~ name ~ ";");
diff --git a/libphobos/libdruntime/core/sys/windows/mmsystem.d b/libphobos/libdruntime/core/sys/windows/mmsystem.d
index 7e7c34ba4f0..29c066e7c97 100644
--- a/libphobos/libdruntime/core/sys/windows/mmsystem.d
+++ b/libphobos/libdruntime/core/sys/windows/mmsystem.d
@@ -1049,7 +1049,7 @@ struct MMTIME {
 }
 alias MMTIME* PMMTIME, LPMMTIME;
 
-alias TypeDef!(HANDLE) HDRVR;
+alias HANDLE HDRVR;
 
 struct DRVCONFIGINFO {
 align(1):
@@ -1083,9 +1083,9 @@ alias MIDICALLBACK* LPMIDICALLBACK;
 
 +/
 
-alias TypeDef!(HANDLE) HWAVE;
-alias TypeDef!(HANDLE) HWAVEIN;
-alias TypeDef!(HANDLE) HWAVEOUT;
+alias HANDLE HWAVE;
+alias HANDLE HWAVEIN;
+alias HANDLE HWAVEOUT;
 
 alias HWAVEIN* LPHWAVEIN;
 alias HWAVEOUT* LPHWAVEOUT;
@@ -1175,10 +1175,10 @@ struct WAVEFORMATEX {
 alias WAVEFORMATEX* PWAVEFORMATEX, LPWAVEFORMATEX;
 alias const(WAVEFORMATEX)* LPCWAVEFORMATEX;
 
-alias TypeDef!(HANDLE) HMIDI;
-alias TypeDef!(HANDLE) HMIDIIN;
-alias TypeDef!(HANDLE) HMIDIOUT;
-alias TypeDef!(HANDLE) HMIDISTRM;
+alias HANDLE HMIDI;
+alias HANDLE HMIDIIN;
+alias HANDLE HMIDIOUT;
+alias HANDLE HMIDISTRM;
 
 alias HMIDI* LPHMIDI;
 alias HMIDIIN* LPHMIDIIN;
@@ -1295,10 +1295,10 @@ struct AUXCAPSW {
 }
 alias AUXCAPSW* PAUXCAPSW, LPAUXCAPSW;
 
-alias TypeDef!(HANDLE) HMIXEROBJ;
+alias HANDLE HMIXEROBJ;
 alias HMIXEROBJ* LPHMIXEROBJ;
 
-alias TypeDef!(HANDLE) HMIXER;
+alias HANDLE HMIXER;
 alias HMIXER* LPHMIXER;
 
 struct MIXERCAPSA {
@@ -1595,7 +1595,7 @@ alias JOYINFOEX* PJOYINFOEX, LPJOYINFOEX;
 alias DWORD FOURCC;
 alias char* HPSTR;
 
-alias TypeDef!(HANDLE) HMMIO;
+alias HANDLE HMMIO;
 
 alias LRESULT function (LPSTR, UINT, LPARAM, LPARAM) LPMMIOPROC;
 
diff --git a/libphobos/libdruntime/core/sys/windows/ole.d b/libphobos/libdruntime/core/sys/windows/ole.d
index c29ec5047ff..a844124bdb7 100644
--- a/libphobos/libdruntime/core/sys/windows/ole.d
+++ b/libphobos/libdruntime/core/sys/windows/ole.d
@@ -257,7 +257,7 @@ struct OLESERVERVTBL {
     OLESTATUS function(LPOLESERVER) Release;
     OLESTATUS function(LPOLESERVER, HGLOBAL) Execute;
 }
-alias TypeDef!(OLESERVERVTBL*) LPOLESERVERVTBL;
+alias OLESERVERVTBL* LPOLESERVERVTBL;
 
 struct OLESERVER {
     LPOLESERVERVTBL lpvtbl;
diff --git a/libphobos/libdruntime/core/sys/windows/ras.d b/libphobos/libdruntime/core/sys/windows/ras.d
index cb69686e9bc..4561799a870 100644
--- a/libphobos/libdruntime/core/sys/windows/ras.d
+++ b/libphobos/libdruntime/core/sys/windows/ras.d
@@ -223,7 +223,7 @@ enum RASPROJECTION {
 }
 alias RASPROJECTION* LPRASPROJECTION;
 
-alias TypeDef!(HANDLE) HRASCONN;
+alias HANDLE HRASCONN;
 alias HRASCONN* LPHRASCONN;
 
 struct RASCONNW {
diff --git a/libphobos/libdruntime/core/sys/windows/rpcdcep.d b/libphobos/libdruntime/core/sys/windows/rpcdcep.d
index cebe9816875..71b82be7a7f 100644
--- a/libphobos/libdruntime/core/sys/windows/rpcdcep.d
+++ b/libphobos/libdruntime/core/sys/windows/rpcdcep.d
@@ -97,7 +97,7 @@ const(void)*          InterpreterInfo;
 }
 alias RPC_CLIENT_INTERFACE* PRPC_CLIENT_INTERFACE;
 
-alias TypeDef!(void*) I_RPC_MUTEX;
+alias void* I_RPC_MUTEX;
 
 struct RPC_TRANSFER_SYNTAX {
     GUID   Uuid;
diff --git a/libphobos/libdruntime/core/sys/windows/rpcndr.d b/libphobos/libdruntime/core/sys/windows/rpcndr.d
index 127d88b5b63..f5744ecdb0c 100644
--- a/libphobos/libdruntime/core/sys/windows/rpcndr.d
+++ b/libphobos/libdruntime/core/sys/windows/rpcndr.d
@@ -387,7 +387,7 @@ enum PROXY_PHASE {
     PROXY_UNMARSHAL
 }
 
-alias TypeDef!(void *) RPC_SS_THREAD_HANDLE;
+alias void * RPC_SS_THREAD_HANDLE;
 
 extern (Windows) {
 alias void function (void*) NDR_RUNDOWN;
diff --git a/libphobos/libdruntime/core/sys/windows/sqltypes.d b/libphobos/libdruntime/core/sys/windows/sqltypes.d
index 28d5f5df1da..e86834faa6d 100644
--- a/libphobos/libdruntime/core/sys/windows/sqltypes.d
+++ b/libphobos/libdruntime/core/sys/windows/sqltypes.d
@@ -32,7 +32,7 @@ alias UDWORD SQLUINTEGER;
 // #endif
 
 //static if (ODBCVER >= 0x0300) {
-alias TypeDef!(HANDLE) SQLHANDLE;
+alias HANDLE SQLHANDLE;
 alias SQLHANDLE SQLHENV, SQLHDBC, SQLHSTMT, SQLHDESC;
 /*
 } else {
diff --git a/libphobos/libdruntime/core/sys/windows/vfw.d b/libphobos/libdruntime/core/sys/windows/vfw.d
index ebe0ed0e03d..e8ca74e888d 100644
--- a/libphobos/libdruntime/core/sys/windows/vfw.d
+++ b/libphobos/libdruntime/core/sys/windows/vfw.d
@@ -38,7 +38,7 @@ DWORD MKFOURCC(char ch0, char ch1, char ch2, char ch3) {
 
 enum ICVERSION = 0x0104;
 
-alias TypeDef!(HANDLE) HIC;
+alias HANDLE HIC;
 
 enum BI_1632 = 0x32333631;
 
@@ -1045,7 +1045,7 @@ DECLARE_INTERFACE_(IAVIStream, IUnknown)
 #endif
 };
 
-alias TypeDef!(IAVIStream FAR*) PAVISTREAM;
+alias IAVIStream FAR* PAVISTREAM;
 
 #undef  INTERFACE
 #define INTERFACE   IAVIStreaming
@@ -1063,7 +1063,7 @@ DECLARE_INTERFACE_(IAVIStreaming, IUnknown)
     STDMETHOD(End)   (THIS) PURE;
 };
 
-alias TypeDef!(IAVIStreaming FAR*) PAVISTREAMING;
+alias IAVIStreaming FAR* PAVISTREAMING;
 
 
 #undef  INTERFACE
@@ -1091,7 +1091,7 @@ DECLARE_INTERFACE_(IAVIEditStream, IUnknown)
                 LONG cbInfo) PURE;
 };
 
-alias TypeDef!(IAVIEditStream FAR*) PAVIEDITSTREAM;
+alias IAVIEditStream FAR* PAVIEDITSTREAM;
 
 #undef  INTERFACE
 #define INTERFACE   IAVIPersistFile
@@ -1101,7 +1101,7 @@ DECLARE_INTERFACE_(IAVIPersistFile, IPersistFile)
     STDMETHOD(Reserved1)(THIS) PURE;
 };
 
-alias TypeDef!(IAVIPersistFile FAR*) PAVIPERSISTFILE;
+alias IAVIPersistFile FAR* PAVIPERSISTFILE;
 
 #undef  INTERFACE
 #define INTERFACE   IAVIFile
@@ -1138,7 +1138,7 @@ DECLARE_INTERFACE_(IAVIFile, IUnknown)
 };
 
 #undef PAVIFILE
-alias TypeDef!(IAVIFile FAR*) PAVIFILE;
+alias IAVIFile FAR* PAVIFILE;
 
 #undef  INTERFACE
 #define INTERFACE   IGetFrame
@@ -1159,7 +1159,7 @@ DECLARE_INTERFACE_(IGetFrame, IUnknown)
 };
 
 #undef PGETFRAME
-alias TypeDef!(IGetFrame FAR*) PGETFRAME;
+alias IGetFrame FAR* PGETFRAME;
 
 #define DEFINE_AVIGUID(name, l, w1, w2)    DEFINE_GUID(name, l, w1, w2, 0xC0,0,0,0,0,0,0,0x46)
 
@@ -1825,7 +1825,7 @@ enum {
     MCI_MODE_OPEN,
 }
 
-alias TypeDef!(HANDLE) HVIDEO;
+alias HANDLE HVIDEO;
 alias HVIDEO* LPHVIDEO;
 
 // Error Return Values
diff --git a/libphobos/libdruntime/core/sys/windows/winbase.d b/libphobos/libdruntime/core/sys/windows/winbase.d
index bbb6e9a7b41..2e32ba25abf 100644
--- a/libphobos/libdruntime/core/sys/windows/winbase.d
+++ b/libphobos/libdruntime/core/sys/windows/winbase.d
@@ -408,7 +408,7 @@ enum : DWORD {
     STD_ERROR_HANDLE  = 0xFFFFFFF4
 }
 
-enum HANDLE INVALID_HANDLE_VALUE = cast(HANDLE) (-1);
+@trusted enum HANDLE INVALID_HANDLE_VALUE = cast(HANDLE) (-1);
 
 enum : DWORD {
     GET_TAPE_MEDIA_INFORMATION = 0,
diff --git a/libphobos/libdruntime/core/sys/windows/wingdi.d b/libphobos/libdruntime/core/sys/windows/wingdi.d
index 5a4eeaa1cd3..c7b0c8bf954 100644
--- a/libphobos/libdruntime/core/sys/windows/wingdi.d
+++ b/libphobos/libdruntime/core/sys/windows/wingdi.d
@@ -2425,11 +2425,11 @@ struct EMRARC {
     POINTL ptlEnd;
 }
 alias EMRARC* PEMRARC;
-alias TypeDef!(EMRARC) EMRARCTO;
+alias EMRARC EMRARCTO;
 alias EMRARCTO* PEMRARCTO;
-alias TypeDef!(EMRARC) EMRCHORD;
+alias EMRARC EMRCHORD;
 alias EMRCHORD* PEMRCHORD;
-alias TypeDef!(EMRARC) EMRPIE;
+alias EMRARC EMRPIE;
 alias EMRPIE* PEMRPIE;
 
 struct XFORM {
@@ -2467,7 +2467,7 @@ struct LOGBRUSH {
     COLORREF lbColor;
     ULONG_PTR lbHatch;
 }
-alias TypeDef!(LOGBRUSH) PATTERN;
+alias LOGBRUSH PATTERN;
 alias LOGBRUSH* PLOGBRUSH, NPLOGBRUSH, LPLOGBRUSH;
 alias PATTERN* PPATTERN, NPPATTERN, LPPATTERN;
 
@@ -2559,9 +2559,9 @@ struct EMRSETCOLORSPACE {
     DWORD ihCS;
 }
 alias EMRSETCOLORSPACE* PEMRSETCOLORSPACE;
-alias TypeDef!(EMRSETCOLORSPACE) EMRSELECTCOLORSPACE;
+alias EMRSETCOLORSPACE EMRSELECTCOLORSPACE;
 alias EMRSELECTCOLORSPACE* PEMRSELECTCOLORSPACE;
-alias TypeDef!(EMRSETCOLORSPACE) EMRDELETECOLORSPACE;
+alias EMRSETCOLORSPACE EMRDELETECOLORSPACE;
 alias EMRDELETECOLORSPACE* PEMRDELETECOLORSPACE;
 
 static if (_WIN32_WINNT >= 0x500) {
@@ -2573,7 +2573,7 @@ static if (_WIN32_WINNT >= 0x500) {
         BYTE[1] EscData;
     }
     alias EMREXTESCAPE* PEMREXTESCAPE;
-    alias TypeDef!(EMREXTESCAPE) EMRDRAWESCAPE;
+    alias EMREXTESCAPE EMRDRAWESCAPE;
     alias EMRDRAWESCAPE* PEMRDRAWESCAPE;
 
     struct EMRNAMEDESCAPE {
@@ -2593,9 +2593,9 @@ static if (_WIN32_WINNT >= 0x500) {
         BYTE[1] Data;
     }
     alias EMRSETICMPROFILE* PEMRSETICMPROFILE;
-    alias TypeDef!(EMRSETICMPROFILE) EMRSETICMPROFILEA;
+    alias EMRSETICMPROFILE EMRSETICMPROFILEA;
     alias EMRSETICMPROFILEA* PEMRSETICMPROFILEA;
-    alias TypeDef!(EMRSETICMPROFILE) EMRSETICMPROFILEW;
+    alias EMRSETICMPROFILE EMRSETICMPROFILEW;
     alias EMRSETICMPROFILEW* PEMRSETICMPROFILEW;
 
     struct EMRCREATECOLORSPACEW {
@@ -2739,7 +2739,7 @@ struct EMRELLIPSE {
 }
 alias EMRELLIPSE* PEMRELLIPSE;
 
-alias TypeDef!(EMRELLIPSE) EMRRECTANGLE;
+alias EMRELLIPSE EMRRECTANGLE;
 alias EMRRECTANGLE* PEMRRECTANGLE;
 
 struct EMREOF {
@@ -2755,7 +2755,7 @@ struct EMREXCLUDECLIPRECT {
     RECTL rclClip;
 }
 alias EMREXCLUDECLIPRECT* PEMREXCLUDECLIPRECT;
-alias TypeDef!(EMREXCLUDECLIPRECT) EMRINTERSECTCLIPRECT;
+alias EMREXCLUDECLIPRECT EMRINTERSECTCLIPRECT;
 alias EMRINTERSECTCLIPRECT* PEMRINTERSECTCLIPRECT;
 
 struct EMREXTCREATEFONTINDIRECTW {
@@ -2833,7 +2833,7 @@ struct EMREXTTEXTOUTA {
     EMRTEXT emrtext;
 }
 alias EMREXTTEXTOUTA* PEMREXTTEXTOUTA;
-alias TypeDef!(EMREXTTEXTOUTA) EMREXTTEXTOUTW;
+alias EMREXTTEXTOUTA EMREXTTEXTOUTW;
 alias EMREXTTEXTOUTW* PEMREXTTEXTOUTW;
 
 struct EMRFILLPATH {
@@ -2842,10 +2842,10 @@ struct EMRFILLPATH {
 }
 alias EMRFILLPATH* PEMRFILLPATH;
 
-alias TypeDef!(EMRFILLPATH) EMRSTROKEANDFILLPATH;
+alias EMRFILLPATH EMRSTROKEANDFILLPATH;
 alias EMRSTROKEANDFILLPATH* PEMRSTROKEANDFILLPATH;
 
-alias TypeDef!(EMRFILLPATH) EMRSTROKEPATH;
+alias EMRFILLPATH EMRSTROKEPATH;
 alias EMRSTROKEPATH* PEMRSTROKEPATH;
 
 struct EMRFILLRGN {
@@ -2889,7 +2889,7 @@ struct EMRINVERTRGN {
     BYTE[1] RgnData;
 }
 alias EMRINVERTRGN* PEMRINVERTRGN;
-alias TypeDef!(EMRINVERTRGN) EMRPAINTRGN;
+alias EMRINVERTRGN EMRPAINTRGN;
 alias EMRPAINTRGN* PEMRPAINTRGN;
 
 struct EMRLINETO {
@@ -2897,7 +2897,7 @@ struct EMRLINETO {
     POINTL ptl;
 }
 alias EMRLINETO* PEMRLINETO;
-alias TypeDef!(EMRLINETO) EMRMOVETOEX;
+alias EMRLINETO EMRMOVETOEX;
 alias EMRMOVETOEX* PEMRMOVETOEX;
 
 struct EMRMASKBLT {
@@ -2990,13 +2990,13 @@ struct EMRPOLYLINE {
     POINTL[1] aptl;
 }
 alias EMRPOLYLINE* PEMRPOLYLINE;
-alias TypeDef!(EMRPOLYLINE) EMRPOLYBEZIER;
+alias EMRPOLYLINE EMRPOLYBEZIER;
 alias EMRPOLYBEZIER* PEMRPOLYBEZIER;
-alias TypeDef!(EMRPOLYLINE) EMRPOLYGON;
+alias EMRPOLYLINE EMRPOLYGON;
 alias EMRPOLYGON* PEMRPOLYGON;
-alias TypeDef!(EMRPOLYLINE) EMRPOLYBEZIERTO;
+alias EMRPOLYLINE EMRPOLYBEZIERTO;
 alias EMRPOLYBEZIERTO* PEMRPOLYBEZIERTO;
-alias TypeDef!(EMRPOLYLINE) EMRPOLYLINETO;
+alias EMRPOLYLINE EMRPOLYLINETO;
 alias EMRPOLYLINETO* PEMRPOLYLINETO;
 
 struct EMRPOLYLINE16 {
@@ -3006,13 +3006,13 @@ struct EMRPOLYLINE16 {
     POINTS[1] apts;
 }
 alias EMRPOLYLINE16* PEMRPOLYLINE16;
-alias TypeDef!(EMRPOLYLINE16) EMRPOLYBEZIER16;
+alias EMRPOLYLINE16 EMRPOLYBEZIER16;
 alias EMRPOLYBEZIER16* PEMRPOLYBEZIER16;
-alias TypeDef!(EMRPOLYLINE16) EMRPOLYGON16;
+alias EMRPOLYLINE16 EMRPOLYGON16;
 alias EMRPOLYGON16* PEMRPOLYGON16;
-alias TypeDef!(EMRPOLYLINE16) EMRPOLYBEZIERTO16;
+alias EMRPOLYLINE16 EMRPOLYBEZIERTO16;
 alias EMRPOLYBEZIERTO16* PEMRPOLYBEZIERTO16;
-alias TypeDef!(EMRPOLYLINE16) EMRPOLYLINETO16;
+alias EMRPOLYLINE16 EMRPOLYLINETO16;
 alias EMRPOLYLINETO16* PEMRPOLYLINETO16;
 
 struct EMRPOLYPOLYLINE {
@@ -3024,7 +3024,7 @@ struct EMRPOLYPOLYLINE {
     POINTL[1] aptl;
 }
 alias EMRPOLYPOLYLINE* PEMRPOLYPOLYLINE;
-alias TypeDef!(EMRPOLYPOLYLINE) EMRPOLYPOLYGON;
+alias EMRPOLYPOLYLINE EMRPOLYPOLYGON;
 alias EMRPOLYPOLYGON* PEMRPOLYPOLYGON;
 
 struct EMRPOLYPOLYLINE16 {
@@ -3036,7 +3036,7 @@ struct EMRPOLYPOLYLINE16 {
     POINTS[1] apts;
 }
 alias EMRPOLYPOLYLINE16* PEMRPOLYPOLYLINE16;
-alias TypeDef!(EMRPOLYPOLYLINE16) EMRPOLYPOLYGON16;
+alias EMRPOLYPOLYLINE16 EMRPOLYPOLYGON16;
 alias EMRPOLYPOLYGON16* PEMRPOLYPOLYGON16;
 
 struct EMRPOLYTEXTOUTA {
@@ -3049,7 +3049,7 @@ struct EMRPOLYTEXTOUTA {
     EMRTEXT[1] aemrtext;
 }
 alias EMRPOLYTEXTOUTA* PEMRPOLYTEXTOUTA;
-alias TypeDef!(EMRPOLYTEXTOUTA) EMRPOLYTEXTOUTW;
+alias EMRPOLYTEXTOUTA EMRPOLYTEXTOUTW;
 alias EMRPOLYTEXTOUTW* PEMRPOLYTEXTOUTW;
 
 struct EMRRESIZEPALETTE {
@@ -3080,7 +3080,7 @@ struct EMRSCALEVIEWPORTEXTEX {
     LONG yDenom;
 }
 alias EMRSCALEVIEWPORTEXTEX* PEMRSCALEVIEWPORTEXTEX;
-alias TypeDef!(EMRSCALEVIEWPORTEXTEX) EMRSCALEWINDOWEXTEX;
+alias EMRSCALEVIEWPORTEXTEX EMRSCALEWINDOWEXTEX;
 alias EMRSCALEWINDOWEXTEX* PEMRSCALEWINDOWEXTEX;
 
 struct EMRSELECTOBJECT {
@@ -3088,7 +3088,7 @@ struct EMRSELECTOBJECT {
     DWORD ihObject;
 }
 alias EMRSELECTOBJECT* PEMRSELECTOBJECT;
-alias TypeDef!(EMRSELECTOBJECT) EMRDELETEOBJECT;
+alias EMRSELECTOBJECT EMRDELETEOBJECT;
 alias EMRDELETEOBJECT* PEMRDELETEOBJECT;
 
 struct EMRSELECTPALETTE {
@@ -3108,7 +3108,7 @@ struct EMRSETTEXTCOLOR {
     COLORREF crColor;
 }
 alias EMRSETTEXTCOLOR* PEMRSETTEXTCOLOR;
-alias TypeDef!(EMRSETTEXTCOLOR) EMRSETBKCOLOR;
+alias EMRSETTEXTCOLOR EMRSETBKCOLOR;
 alias EMRSETBKCOLOR* PEMRSETBKCOLOR;
 
 struct EMRSETCOLORADJUSTMENT {
@@ -3169,7 +3169,7 @@ struct EMRSETVIEWPORTEXTEX {
     SIZEL szlExtent;
 }
 alias EMRSETVIEWPORTEXTEX* PEMRSETVIEWPORTEXTEX;
-alias TypeDef!(EMRSETVIEWPORTEXTEX) EMRSETWINDOWEXTEX;
+alias EMRSETVIEWPORTEXTEX EMRSETWINDOWEXTEX;
 alias EMRSETWINDOWEXTEX* PEMRSETWINDOWEXTEX;
 
 struct EMRSETVIEWPORTORGEX {
@@ -3177,9 +3177,9 @@ struct EMRSETVIEWPORTORGEX {
     POINTL ptlOrigin;
 }
 alias EMRSETVIEWPORTORGEX* PEMRSETVIEWPORTORGEX;
-alias TypeDef!(EMRSETVIEWPORTORGEX) EMRSETWINDOWORGEX;
+alias EMRSETVIEWPORTORGEX EMRSETWINDOWORGEX;
 alias EMRSETWINDOWORGEX* PEMRSETWINDOWORGEX;
-alias TypeDef!(EMRSETVIEWPORTORGEX) EMRSETBRUSHORGEX;
+alias EMRSETVIEWPORTORGEX EMRSETBRUSHORGEX;
 alias EMRSETBRUSHORGEX* PEMRSETBRUSHORGEX;
 
 struct EMRSETWORLDTRANSFORM {
@@ -3234,21 +3234,21 @@ struct EMRABORTPATH {
     EMR emr;
 }
 alias EMRABORTPATH* PEMRABORTPATH;
-alias TypeDef!(EMRABORTPATH) EMRBEGINPATH;
+alias EMRABORTPATH EMRBEGINPATH;
 alias EMRBEGINPATH* PEMRBEGINPATH;
-alias TypeDef!(EMRABORTPATH) EMRENDPATH;
+alias EMRABORTPATH EMRENDPATH;
 alias EMRENDPATH* PEMRENDPATH;
-alias TypeDef!(EMRABORTPATH) EMRCLOSEFIGURE;
+alias EMRABORTPATH EMRCLOSEFIGURE;
 alias EMRCLOSEFIGURE* PEMRCLOSEFIGURE;
-alias TypeDef!(EMRABORTPATH) EMRFLATTENPATH;
+alias EMRABORTPATH EMRFLATTENPATH;
 alias EMRFLATTENPATH* PEMRFLATTENPATH;
-alias TypeDef!(EMRABORTPATH) EMRWIDENPATH;
+alias EMRABORTPATH EMRWIDENPATH;
 alias EMRWIDENPATH* PEMRWIDENPATH;
-alias TypeDef!(EMRABORTPATH) EMRSETMETARGN;
+alias EMRABORTPATH EMRSETMETARGN;
 alias EMRSETMETARGN* PEMRSETMETARGN;
-alias TypeDef!(EMRABORTPATH) EMRSAVEDC;
+alias EMRABORTPATH EMRSAVEDC;
 alias EMRSAVEDC* PEMRSAVEDC;
-alias TypeDef!(EMRABORTPATH) EMRREALIZEPALETTE;
+alias EMRABORTPATH EMRREALIZEPALETTE;
 alias EMRREALIZEPALETTE* PEMRREALIZEPALETTE;
 
 struct EMRSELECTCLIPPATH {
@@ -3256,24 +3256,24 @@ struct EMRSELECTCLIPPATH {
     DWORD iMode;
 }
 alias EMRSELECTCLIPPATH* PEMRSELECTCLIPPATH;
-alias TypeDef!(EMRSELECTCLIPPATH) EMRSETBKMODE;
+alias EMRSELECTCLIPPATH EMRSETBKMODE;
 alias EMRSETBKMODE* PEMRSETBKMODE;
-alias TypeDef!(EMRSELECTCLIPPATH) EMRSETMAPMODE;
+alias EMRSELECTCLIPPATH EMRSETMAPMODE;
 alias EMRSETMAPMODE* PEMRSETMAPMODE;
-alias TypeDef!(EMRSELECTCLIPPATH) EMRSETPOLYFILLMODE;
+alias EMRSELECTCLIPPATH EMRSETPOLYFILLMODE;
 alias EMRSETPOLYFILLMODE* PEMRSETPOLYFILLMODE;
-alias TypeDef!(EMRSELECTCLIPPATH) EMRSETROP2;
+alias EMRSELECTCLIPPATH EMRSETROP2;
 alias EMRSETROP2* PEMRSETROP2;
-alias TypeDef!(EMRSELECTCLIPPATH) EMRSETSTRETCHBLTMODE;
+alias EMRSELECTCLIPPATH EMRSETSTRETCHBLTMODE;
 alias EMRSETSTRETCHBLTMODE* PEMRSETSTRETCHBLTMODE;
-alias TypeDef!(EMRSELECTCLIPPATH) EMRSETICMMODE;
+alias EMRSELECTCLIPPATH EMRSETICMMODE;
 alias EMRSETICMMODE* PEMRSETICMMODE;
-alias TypeDef!(EMRSELECTCLIPPATH) EMRSETTEXTALIGN;
+alias EMRSELECTCLIPPATH EMRSETTEXTALIGN;
 alias EMRSETTEXTALIGN* PEMRSETTEXTALIGN;
-alias TypeDef!(EMRSELECTCLIPPATH) EMRENABLEICM;
+alias EMRSELECTCLIPPATH EMRENABLEICM;
 alias EMRENABLEICM* PEMRENABLEICM;
 static if (_WIN32_WINNT >= 0x500) {
-    alias TypeDef!(EMRSELECTCLIPPATH) EMRSETLAYOUT;
+    alias EMRSELECTCLIPPATH EMRSETLAYOUT;
     alias EMRSETLAYOUT* PEMRSETLAYOUT;
 }
 
diff --git a/libphobos/libdruntime/core/sys/windows/winuser.d b/libphobos/libdruntime/core/sys/windows/winuser.d
index 71cd8827d22..829952dfdb5 100644
--- a/libphobos/libdruntime/core/sys/windows/winuser.d
+++ b/libphobos/libdruntime/core/sys/windows/winuser.d
@@ -3421,7 +3421,7 @@ align(4) LUID  luid;
     }
     alias BSMINFO* PBSMINFO;
 
-    alias TypeDef!(HANDLE) HRAWINPUT;
+    alias HANDLE HRAWINPUT;
 
     struct RAWINPUTHEADER {
         DWORD dwType;
@@ -4155,7 +4155,7 @@ extern (C) {
 
 
 // These shouldn't be necessary for D.
-alias TypeDef!(char*) va_list_;
+alias char* va_list_;
 int wvsprintfA(LPSTR, LPCSTR, va_list_ arglist);
 int wvsprintfW(LPWSTR, LPCWSTR, va_list_ arglist);
 
diff --git a/libphobos/libdruntime/object.d b/libphobos/libdruntime/object.d
index b0889b66386..f3af2097b39 100644
--- a/libphobos/libdruntime/object.d
+++ b/libphobos/libdruntime/object.d
@@ -748,7 +748,7 @@ class TypeInfo
 
     /** Return info used by the garbage collector to do precise collection.
      */
-    @property immutable(void)* rtInfo() nothrow pure const @safe @nogc { return rtinfoHasPointers; } // better safe than sorry
+    @property immutable(void)* rtInfo() nothrow pure const @trusted @nogc { return rtinfoHasPointers; } // better safe than sorry
 }
 
 @system unittest
@@ -2929,6 +2929,25 @@ void clear(Value, Key)(Value[Key]* aa)
     assert("k1" !in aa);
 }
 
+// Issue 20559
+@system unittest
+{
+    static class Foo
+    {
+        int[string] aa;
+        alias aa this;
+    }
+
+    auto v = new Foo();
+    v["Hello World"] = 42;
+    v.clear;
+    assert("Hello World" !in v);
+
+    // Test for T*
+    static assert(!__traits(compiles, (&v).clear));
+    static assert( __traits(compiles, (*(&v)).clear));
+}
+
 /***********************************
  * Reorganizes the associative array in place so that lookups are more
  * efficient.
@@ -4292,6 +4311,44 @@ void destroy(bool initialize = true, T)(T obj) if (is(T == interface))
     destroy!true(new C());
 }
 
+@system unittest
+{
+    // class with an `alias this`
+    class A
+    {
+        static int dtorCount;
+        ~this()
+        {
+            dtorCount++;
+        }
+    }
+
+    class B
+    {
+        A a;
+        alias a this;
+        this()
+        {
+            a = new A;
+        }
+        static int dtorCount;
+        ~this()
+        {
+            dtorCount++;
+        }
+    }
+    auto b = new B;
+    assert(A.dtorCount == 0);
+    assert(B.dtorCount == 0);
+    destroy(b);
+    assert(A.dtorCount == 0);
+    assert(B.dtorCount == 1);
+
+    auto a = new A;
+    destroy(a);
+    assert(A.dtorCount == 1);
+}
+
 @system unittest
 {
     interface I { }
@@ -4505,6 +4562,43 @@ if (__traits(isStaticArray, T))
     }
 }
 
+// https://issues.dlang.org/show_bug.cgi?id=19218
+@system unittest
+{
+    static struct S
+    {
+        static dtorCount = 0;
+        ~this() { ++dtorCount; }
+    }
+
+    static interface I
+    {
+        ref S[3] getArray();
+        alias getArray this;
+    }
+
+    static class C : I
+    {
+        static dtorCount = 0;
+        ~this() { ++dtorCount; }
+
+        S[3] a;
+        alias a this;
+
+        ref S[3] getArray() { return a; }
+    }
+
+    C c = new C();
+    destroy(c);
+    assert(S.dtorCount == 3);
+    assert(C.dtorCount == 1);
+
+    I i = new C();
+    destroy(i);
+    assert(S.dtorCount == 6);
+    assert(C.dtorCount == 2);
+}
+
 /// ditto
 void destroy(bool initialize = true, T)(ref T obj)
     if (!is(T == struct) && !is(T == interface) && !is(T == class) && !__traits(isStaticArray, T))
diff --git a/libphobos/src/MERGE b/libphobos/src/MERGE
index a5414f16cd3..0424d7b0cfa 100644
--- a/libphobos/src/MERGE
+++ b/libphobos/src/MERGE
@@ -1,4 +1,4 @@
-330d6a4fdbe82683e081959d0aeb53597b025bc4
+d7e79f024606f18e989ae8b5fe298f9d07c7dced
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/phobos repository.
diff --git a/libphobos/src/std/array.d b/libphobos/src/std/array.d
index 26528032ded..a613a8d9e4a 100644
--- a/libphobos/src/std/array.d
+++ b/libphobos/src/std/array.d
@@ -4700,24 +4700,16 @@ unittest
 }
 
 /++
-Constructs a static array from `a`.
-The type of elements can be specified implicitly so that $(D [1, 2].staticArray) results in `int[2]`,
-or explicitly, e.g. $(D [1, 2].staticArray!float) returns `float[2]`.
-When `a` is a range whose length is not known at compile time, the number of elements must be
-given as template argument (e.g. `myrange.staticArray!2`).
-Size and type can be combined, if the source range elements are implicitly
-convertible to the requested element type (eg: `2.iota.staticArray!(long[2])`).
-When the range `a` is known at compile time, it can also be specified as a
-template argument to avoid having to specify the number of elements
-(e.g.: `staticArray!(2.iota)` or `staticArray!(double, 2.iota)`).
+Constructs a static array from a dynamic array whose length is known at compile-time.
+The element type can be inferred or specified explicitly:
+
+* $(D [1, 2].staticArray) returns `int[2]`
+* $(D [1, 2].staticArray!float) returns `float[2]`
 
 Note: `staticArray` returns by value, so expressions involving large arrays may be inefficient.
 
 Params:
-    a = The input elements. If there are less elements than the specified length of the static array,
-    the rest of it is default-initialized. If there are more than specified, the first elements
-    up to the specified length are used.
-    rangeLength = outputs the number of elements used from `a` to it. Optional.
+    a = The input array.
 
 Returns: A static array constructed from `a`.
 +/
@@ -4774,7 +4766,23 @@ nothrow pure @safe @nogc unittest
     [cast(byte) 1, cast(byte) 129].staticArray.checkStaticArray!byte([1, -127]);
 }
 
-/// ditto
+/**
+Constructs a static array from a range.
+When `a.length` is not known at compile time, the number of elements must be
+given as a template argument (e.g. `myrange.staticArray!2`).
+Size and type can be combined, if the source range elements are implicitly
+convertible to the requested element type (eg: `2.iota.staticArray!(long[2])`).
+
+When the range `a` is known at compile time, it can be given as a
+template argument to avoid having to specify the number of elements
+(e.g.: `staticArray!(2.iota)` or `staticArray!(double, 2.iota)`).
+
+Params:
+    a = The input range. If there are less elements than the specified length of the static array,
+    the rest of it is default-initialized. If there are more than specified, the first elements
+    up to the specified length are used.
+    rangeLength = Output for the number of elements used from `a`. Optional.
+*/
 auto staticArray(size_t n, T)(scope T a)
 if (isInputRange!T)
 {
diff --git a/libphobos/src/std/conv.d b/libphobos/src/std/conv.d
index aabcd784229..4248e4b9d44 100644
--- a/libphobos/src/std/conv.d
+++ b/libphobos/src/std/conv.d
@@ -190,8 +190,9 @@ Conversions from string _to numeric types differ from the C equivalents
 `atoi()` and `atol()` by checking for overflow and not allowing whitespace.
 
 For conversion of strings _to signed types, the grammar recognized is:
-$(PRE $(I Integer): $(I Sign UnsignedInteger)
-$(I UnsignedInteger)
+$(PRE $(I Integer):
+    $(I Sign UnsignedInteger)
+    $(I UnsignedInteger)
 $(I Sign):
     $(B +)
     $(B -))
@@ -260,7 +261,7 @@ template to(T)
 }
 
 /**
- * When converting strings _to numeric types, note that the D hexadecimal and binary
+ * When converting strings _to numeric types, note that D hexadecimal and binary
  * literals are not handled. Neither the prefixes that indicate the base, nor the
  * horizontal bar used _to separate groups of digits are recognized. This also
  * applies to the suffixes that indicate the type.
@@ -397,7 +398,7 @@ template to(T)
  *   $(LI Pointer to string conversions convert the pointer to a `size_t` value.
  *        If pointer is `char*`, treat it as C-style strings.
  *        In that case, this function is `@system`.))
- * See $(REF formatValue, std,format) on how toString should be defined.
+ * See $(REF formatValue, std,format) on how `toString` should be defined.
  */
 @system pure unittest // @system due to cast and ptr
 {
@@ -423,6 +424,22 @@ template to(T)
     assert(c == "abcx");
 }
 
+/**
+ * Strings can be converted to enum types. The enum member with the same name as the
+ * input string is returned. The comparison is case-sensitive.
+ *
+ * A $(LREF ConvException) is thrown if the enum does not have the specified member.
+ */
+@safe pure unittest
+{
+    import std.exception : assertThrown;
+
+    enum E { a, b, c }
+    assert(to!E("a") == E.a);
+    assert(to!E("b") == E.b);
+    assertThrown!ConvException(to!E("A"));
+}
+
 // Tests for https://issues.dlang.org/show_bug.cgi?id=6175
 @safe pure nothrow unittest
 {
@@ -2247,19 +2264,21 @@ template roundTo(Target)
 }
 
 /**
-The `parse` family of functions works quite like the `to`
+$(PANEL
+The `parse` family of functions works quite like the $(LREF to)
 family, except that:
 $(OL
     $(LI It only works with character ranges as input.)
-    $(LI It takes the input by reference. (This means that rvalues - such
-    as string literals - are not accepted: use `to` instead.))
+    $(LI It takes the input by reference. This means that rvalues (such
+    as string literals) are not accepted: use `to` instead.)
     $(LI It advances the input to the position following the conversion.)
     $(LI It does not throw if it could not convert the entire input.))
+)
 
-This overload converts a character input range to a `bool`.
+This overload parses a `bool` from a character input range.
 
 Params:
-    Target = the type to convert to
+    Target = the boolean type to convert to
     source = the lvalue of an $(REF_ALTTEXT input range, isInputRange, std,range,primitives)
     doCount = the flag for deciding to report the number of consumed characters
 
@@ -2276,9 +2295,9 @@ Note:
     to `parse` and do not require lvalues.
 */
 auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source source)
-if (isInputRange!Source &&
-    isSomeChar!(ElementType!Source) &&
-    is(immutable Target == immutable bool))
+if (is(immutable Target == immutable bool) &&
+    isInputRange!Source &&
+    isSomeChar!(ElementType!Source))
 {
     import std.ascii : toLower;
 
@@ -2377,8 +2396,7 @@ Lerr:
 }
 
 /**
-Parses a character $(REF_ALTTEXT input range, isInputRange, std,range,primitives)
-to an integral value.
+Parses an integer from a character $(REF_ALTTEXT input range, isInputRange, std,range,primitives).
 
 Params:
     Target = the integral type to convert to
@@ -2395,8 +2413,8 @@ Throws:
     if no character of the input was meaningfully converted.
 */
 auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref scope Source s)
-if (isSomeChar!(ElementType!Source) &&
-    isIntegral!Target && !is(Target == enum))
+if (isIntegral!Target && !is(Target == enum) &&
+    isSomeChar!(ElementType!Source))
 {
     static if (Target.sizeof < int.sizeof)
     {
@@ -2817,8 +2835,8 @@ Lerr:
 
 /// ditto
 auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source source, uint radix)
-if (isSomeChar!(ElementType!Source) &&
-    isIntegral!Target && !is(Target == enum))
+if (isIntegral!Target && !is(Target == enum) &&
+    isSomeChar!(ElementType!Source))
 in
 {
     assert(radix >= 2 && radix <= 36, "radix must be in range [2,36]");
@@ -2969,7 +2987,7 @@ do
 }
 
 /**
- * Takes a string representing an `enum` type and returns that type.
+ * Parses an `enum` type from a string representing an enum member name.
  *
  * Params:
  *     Target = the `enum` type to convert to
@@ -2986,8 +3004,7 @@ do
  *     represented by `s`.
  */
 auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s)
-if (isSomeString!Source && !is(Source == enum) &&
-    is(Target == enum))
+if (is(Target == enum) && isSomeString!Source && !is(Source == enum))
 {
     import std.algorithm.searching : startsWith;
     import std.traits : Unqual, EnumMembers;
@@ -3079,7 +3096,7 @@ if (isSomeString!Source && !is(Source == enum) &&
 }
 
 /**
- * Parses a character range to a floating point number.
+ * Parses a floating point number from a character range.
  *
  * Params:
  *     Target = a floating point type
@@ -3097,8 +3114,8 @@ if (isSomeString!Source && !is(Source == enum) &&
  *     parsed, or if an overflow occurred.
  */
 auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source source)
-if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum) &&
-    isFloatingPoint!Target && !is(Target == enum))
+if (isFloatingPoint!Target && !is(Target == enum) &&
+    isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum))
 {
     import std.ascii : isDigit, isAlpha, toLower, toUpper, isHexDigit;
     import std.exception : enforce;
@@ -3790,7 +3807,7 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum
 }
 
 /**
-Parsing one character off a range returns the first element and calls `popFront`.
+Parses one character from a character range.
 
 Params:
     Target = the type to convert to
@@ -3806,8 +3823,8 @@ Throws:
     A $(LREF ConvException) if the range is empty.
  */
 auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s)
-if (isSomeString!Source && !is(Source == enum) &&
-    staticIndexOf!(immutable Target, immutable dchar, immutable ElementEncodingType!Source) >= 0)
+if (staticIndexOf!(immutable Target, immutable dchar, immutable ElementEncodingType!Source) >= 0 &&
+    isSomeString!Source && !is(Source == enum))
 {
     if (s.empty)
         throw convError!(Source, Target)(s);
@@ -3863,8 +3880,8 @@ if (isSomeString!Source && !is(Source == enum) &&
 
 /// ditto
 auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s)
-if (!isSomeString!Source && isInputRange!Source && isSomeChar!(ElementType!Source) &&
-    isSomeChar!Target && Target.sizeof >= ElementType!Source.sizeof && !is(Target == enum))
+if (isSomeChar!Target && Target.sizeof >= ElementType!Source.sizeof && !is(Target == enum) &&
+    !isSomeString!Source && isInputRange!Source && isSomeChar!(ElementType!Source))
 {
     if (s.empty)
         throw convError!(Source, Target)(s);
@@ -3931,7 +3948,7 @@ if (!isSomeString!Source && isInputRange!Source && isSomeChar!(ElementType!Sourc
 }
 
 /**
-Parsing a character range to `typeof(null)` returns `null` if the range
+Parses `typeof(null)` from a character range if the range
 spells `"null"`. This function is case insensitive.
 
 Params:
@@ -3948,9 +3965,9 @@ Throws:
     A $(LREF ConvException) if the range doesn't represent `null`.
  */
 auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s)
-if (isInputRange!Source &&
-    isSomeChar!(ElementType!Source) &&
-    is(immutable Target == immutable typeof(null)))
+if (is(immutable Target == immutable typeof(null)) &&
+    isInputRange!Source &&
+    isSomeChar!(ElementType!Source))
 {
     import std.ascii : toLower;
     foreach (c; "null")
@@ -4062,8 +4079,8 @@ package auto skipWS(R, Flag!"doCount" doCount = No.doCount)(ref R r)
  */
 auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s, dchar lbracket = '[',
     dchar rbracket = ']', dchar comma = ',')
-if (isSomeString!Source && !is(Source == enum) &&
-    isDynamicArray!Target && !is(Target == enum))
+if (isDynamicArray!Target && !is(Target == enum) &&
+    isSomeString!Source && !is(Source == enum))
 {
     import std.array : appender;
 
@@ -4249,8 +4266,8 @@ if (isSomeString!Source && !is(Source == enum) &&
 /// ditto
 auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s, dchar lbracket = '[',
     dchar rbracket = ']', dchar comma = ',')
-if (isExactSomeString!Source &&
-    isStaticArray!Target && !is(Target == enum))
+if (isStaticArray!Target && !is(Target == enum) &&
+    isExactSomeString!Source)
 {
     static if (hasIndirections!Target)
         Target result = Target.init[0].init;
@@ -4358,8 +4375,8 @@ Lfewerr:
  */
 auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s, dchar lbracket = '[',
                              dchar rbracket = ']', dchar keyval = ':', dchar comma = ',')
-if (isSomeString!Source && !is(Source == enum) &&
-    isAssociativeArray!Target && !is(Target == enum))
+if (isAssociativeArray!Target && !is(Target == enum) &&
+    isSomeString!Source && !is(Source == enum))
 {
     alias KeyType = typeof(Target.init.keys[0]);
     alias ValType = typeof(Target.init.values[0]);
diff --git a/libphobos/src/std/digest/md.d b/libphobos/src/std/digest/md.d
index 0c4e42b5f7e..f4d6200b129 100644
--- a/libphobos/src/std/digest/md.d
+++ b/libphobos/src/std/digest/md.d
@@ -295,7 +295,8 @@ struct MD5
          */
         void put(scope const(ubyte)[] data...) @trusted pure nothrow @nogc
         {
-            uint i, index, partLen;
+            size_t i;
+            uint index, partLen;
             auto inputLen = data.length;
 
             //Compute number of bytes mod 64
diff --git a/libphobos/src/std/digest/sha.d b/libphobos/src/std/digest/sha.d
index 5bbf7ea20c3..5c7c3d5dab1 100644
--- a/libphobos/src/std/digest/sha.d
+++ b/libphobos/src/std/digest/sha.d
@@ -650,7 +650,9 @@ struct SHA(uint hashBlockSize, uint digestSize)
         void put(scope const(ubyte)[] input...) @trusted pure nothrow @nogc
         {
             enum blockSizeInBytes = blockSize/8;
-            uint i, index, partLen;
+
+            size_t i;
+            uint index, partLen;
             auto inputLen = input.length;
 
             /* Compute number of bytes mod block size (64 or 128 bytes) */
diff --git a/libphobos/src/std/exception.d b/libphobos/src/std/exception.d
index 1d93d351d99..5c786859c8e 100644
--- a/libphobos/src/std/exception.d
+++ b/libphobos/src/std/exception.d
@@ -416,13 +416,16 @@ void assertThrown(T : Throwable = Exception, E)
     Returns: `value`, if `cast(bool) value` is true. Otherwise,
     depending on the chosen overload, `new Exception(msg)`, `dg()` or `ex` is thrown.
 
-    Note:
-        `enforce` is used to throw exceptions and is therefore intended to
+        $(PANEL
+        $(NOTE `enforce` is used to throw exceptions and is therefore intended to
         aid in error handling. It is $(I not) intended for verifying the logic
-        of your program. That is what `assert` is for. Also, do not use
+        of your program - that is what `assert` is for.)
+
+        Do not use
         `enforce` inside of contracts (i.e. inside of `in` and `out`
         blocks and `invariant`s), because contracts are compiled out when
         compiling with $(I -release).
+        )
 
         If a delegate is passed, the safety and purity of this function are inferred
         from `Dg`'s safety and purity.
@@ -836,7 +839,7 @@ string letters()
 )
 
 The use in the example above is correct because `result`
-was private to `letters` and is inaccessible in writing
+was private to `letters` and the memory it referenced can no longer be written to
 after the function returns. The following example shows an
 incorrect use of `assumeUnique`.
 
@@ -859,8 +862,8 @@ string letters(char first, char last)
 ----
 )
 
-The example above wreaks havoc on client code because it is
-modifying arrays that callers considered immutable. To obtain an
+The example above wreaks havoc on client code because it modifies the
+returned array that the previous caller considered immutable. To obtain an
 immutable array from the writable array `buffer`, replace
 the last line with:
 
@@ -868,13 +871,14 @@ the last line with:
 return to!(string)(sneaky); // not that sneaky anymore
 ----
 
-The call will duplicate the array appropriately.
+The `to` call will duplicate the array appropriately.
 
-Note that checking for uniqueness during compilation is
+$(PANEL
+$(NOTE Checking for uniqueness during compilation is
 possible in certain cases, especially when a function is
-marked as a pure function. The following example does not
+marked (or inferred) as `pure`. The following example does not
 need to call `assumeUnique` because the compiler can infer the
-uniqueness of the array in the pure function:
+uniqueness of the array in the pure function:)
 
 $(RUNNABLE_EXAMPLE
 ----
@@ -894,6 +898,7 @@ For more on infering uniqueness see the $(B unique) and
 $(B lent) keywords in the
 $(HTTP www.cs.cmu.edu/~aldrich/papers/aldrich-dissertation.pdf, ArchJava)
 language.
+)
 
 The downside of using `assumeUnique`'s
 convention-based usage is that at this time there is no
diff --git a/libphobos/src/std/format/internal/write.d b/libphobos/src/std/format/internal/write.d
index 8eb70eaa268..85954faa35e 100644
--- a/libphobos/src/std/format/internal/write.d
+++ b/libphobos/src/std/format/internal/write.d
@@ -2529,35 +2529,37 @@ if ((is(T == struct) || is(T == union)) && (hasToString!(T, Char) || !is(Builtin
         enum right = ")";
 
         put(w, left);
-        foreach (i, e; val.tupleof)
-        {
+        static foreach (i; 0 .. T.tupleof.length)
+        {{
             static if (__traits(identifier, val.tupleof[i]) == "this")
-                continue;
-            else static if (0 < i && val.tupleof[i-1].offsetof == val.tupleof[i].offsetof)
             {
-                static if (i == val.tupleof.length - 1 || val.tupleof[i].offsetof != val.tupleof[i+1].offsetof)
+                // ignore hidden context pointer
+            }
+            else static if (0 < i && T.tupleof[i-1].offsetof == T.tupleof[i].offsetof)
+            {
+                static if (i == T.tupleof.length - 1 || T.tupleof[i].offsetof != T.tupleof[i+1].offsetof)
                 {
-                    enum el = separator ~ val.tupleof[i].stringof[4 .. $] ~ "}";
+                    enum el = separator ~ __traits(identifier, T.tupleof[i]) ~ "}";
                     put(w, el);
                 }
                 else
                 {
-                    enum el = separator ~ val.tupleof[i].stringof[4 .. $];
+                    enum el = separator ~ __traits(identifier, T.tupleof[i]);
                     put(w, el);
                 }
             }
-            else static if (i+1 < val.tupleof.length && val.tupleof[i].offsetof == val.tupleof[i+1].offsetof)
+            else static if (i+1 < T.tupleof.length && T.tupleof[i].offsetof == T.tupleof[i+1].offsetof)
             {
-                enum el = (i > 0 ? separator : "") ~ "#{overlap " ~ val.tupleof[i].stringof[4 .. $];
+                enum el = (i > 0 ? separator : "") ~ "#{overlap " ~ __traits(identifier, T.tupleof[i]);
                 put(w, el);
             }
             else
             {
                 static if (i > 0)
                     put(w, separator);
-                formatElement(w, e, f);
+                formatElement(w, val.tupleof[i], f);
             }
-        }
+        }}
         put(w, right);
     }
     else
@@ -2660,7 +2662,7 @@ if ((is(T == struct) || is(T == union)) && (hasToString!(T, Char) || !is(Builtin
     {
         int n;
         string s;
-        string toString() const { return s; }
+        string toString() @trusted const { return s; }
     }
     U2 u2;
     () @trusted { u2.s = "hello"; } ();
diff --git a/libphobos/src/std/int128.d b/libphobos/src/std/int128.d
index fc992f82422..b20fa1fdddc 100644
--- a/libphobos/src/std/int128.d
+++ b/libphobos/src/std/int128.d
@@ -18,8 +18,8 @@ private import core.int128;
 
 public struct Int128
 {
-  @safe pure nothrow @nogc:
-
+  @safe pure nothrow @nogc
+  {
     Cent data;          /// core.int128.Cent
 
     /****************
@@ -153,6 +153,7 @@ public struct Int128
     {
         return tst(this.data);
     }
+  } // @safe pure nothrow @nogc
 
     /** Support binary arithmetic operators + - * / % & | ^ << >> >>>
      * Params:
@@ -190,21 +191,49 @@ public struct Int128
     }
 
     /// ditto
-    Int128 opBinary(string op)(long op2) const
-        if (op == "+" || op == "-" ||
+    Int128 opBinary(string op, Int)(const Int op2) const
+        if ((op == "+" || op == "-" ||
             op == "*" || op == "/" || op == "%" ||
-            op == "&" || op == "|" || op == "^")
+            op == "&" || op == "|" || op == "^") &&
+            is(Int : long) && __traits(isIntegral, Int))
     {
-        return mixin("this " ~ op ~ " Int128(0, op2)");
+        static if (__traits(isUnsigned, Int))
+            return mixin("this " ~ op ~ " Int128(0, op2)");
+        else
+            return mixin("this " ~ op ~ " Int128((cast(long) op2) >> 63 , op2)");
     }
 
     /// ditto
-    Int128 opBinaryRight(string op)(long op2) const
-        if (op == "+" || op == "-" ||
+    Int128 opBinary(string op, IntLike)(auto ref IntLike op2) const
+        if ((op == "+" || op == "-" ||
             op == "*" || op == "/" || op == "%" ||
-            op == "&" || op == "|" || op == "^")
+            op == "&" || op == "|" || op == "^") &&
+            is(IntLike : long) && !__traits(isIntegral, IntLike))
+    {
+        return opBinary!(op)(__traits(getMember, op2, __traits(getAliasThis, IntLike)[0]));
+    }
+
+    /// ditto
+    Int128 opBinaryRight(string op, Int)(const Int op2) const
+        if ((op == "+" || op == "-" ||
+            op == "*" || op == "/" || op == "%" ||
+            op == "&" || op == "|" || op == "^") &&
+            is(Int : long) && __traits(isIntegral, Int))
+    {
+        static if (__traits(isUnsigned, Int))
+            mixin("return Int128(0, op2) " ~ op ~ " this;");
+        else
+            mixin("return Int128((cast(long) op2) >> 63, op2) " ~ op ~ " this;");
+    }
+
+    /// ditto
+    Int128 opBinaryRight(string op, IntLike)(auto ref IntLike op2) const
+        if ((op == "+" || op == "-" ||
+            op == "*" || op == "/" || op == "%" ||
+            op == "&" || op == "|" || op == "^") &&
+            is(IntLike : long) && !__traits(isIntegral, IntLike))
     {
-        mixin("return Int128(0, op2) " ~ op ~ " this;");
+        return opBinaryRight!(op)(__traits(getMember, op2, __traits(getAliasThis, IntLike)[0]));
     }
 
     /// ditto
@@ -244,32 +273,182 @@ public struct Int128
     }
 
     /// ditto
-    ref Int128 opOpAssign(string op)(long op2)
-        if (op == "+" || op == "-" ||
+    ref Int128 opOpAssign(string op, Int)(auto ref Int op2)
+        if ((op == "+" || op == "-" ||
             op == "*" || op == "/" || op == "%" ||
             op == "&" || op == "|" || op == "^" ||
             op == "<<" || op == ">>" || op == ">>>")
+            && is(Int : long))
     {
         mixin("this = this " ~ op ~ " op2;");
         return this;
     }
 
-    /** support signed arithmentic comparison operators < <= > >=
+    /** support arithmentic comparison operators < <= > >=
      * Params: op2 = right hand operand
      * Returns: -1 for less than, 0 for equals, 1 for greater than
      */
-    int opCmp(Int128 op2) const
+    int opCmp(Int128 op2) const @nogc nothrow pure @safe
     {
         return this == op2 ? 0 : gt(this.data, op2.data) * 2 - 1;
     }
 
-    /** support signed arithmentic comparison operators < <= > >=
-     * Params: op2 = right hand operand
-     * Returns: -1 for less than, 0 for equals, 1 for greater than
+    /// ditto
+    int opCmp(Int)(const Int op2) const @nogc nothrow pure @safe
+    if (is(Int : long) && __traits(isIntegral, Int))
+    {
+        static if (__traits(isUnsigned, Int))
+            return opCmp(Int128(0, op2));
+        else
+            return opCmp(Int128((cast(long) op2) >> 63, op2));
+    }
+
+    /// ditto
+    int opCmp(IntLike)(auto ref IntLike op2) const
+    if (is(IntLike : long) && !__traits(isIntegral, IntLike))
+    {
+        return opCmp(__traits(getMember, op2, __traits(getAliasThis, IntLike)[0]));
+    }
+
+    /**
+     * Formats `Int128` with either `%d`, `%x`, `%X`, or `%s` (same as `%d`).
+     *
+     * Params:
+     *   sink = $(REF_ALTTEXT Output range, isOutputRange, std, range, primitives)
+     *   to write to.
+     *   fmt = A $(REF FormatSpec, std,format) which controls how the number
+     *   is displayed.
+     *
+     * Throws:
+     *       $(REF FormatException, std,format) if the format specifier is
+     *       not one of 'd', 'x', 'X', 's'.
+     *
+     * See_Also: $(REF formatValue, std,format)
      */
-    int opCmp(long op2) const
+    void toString(Writer, FormatSpec)(scope ref Writer sink, scope const ref FormatSpec fmt) const
     {
-        return opCmp(Int128(0, op2));
+        import std.range.primitives : put;
+        import std.format : FormatException, Fmt = FormatSpec;
+
+        static if (is(FormatSpec == Fmt!Char, Char))
+        {
+            // Puts "Char" into scope if the pattern matches.
+        }
+        static assert(is(Char),
+            "Expecting `FormatSpec` to be instantiation of `std.format.FormatSpec`");
+
+        Char[39] buf = void;
+        size_t bufStart = void;
+        Char signChar = 0;
+        if (fmt.spec == 'd' || fmt.spec == 's')
+        {
+            const bool isNeg = 0 > cast(long) this.data.hi;
+            Cent val = isNeg ? neg(this.data) : this.data;
+            immutable Cent radix = { lo: 10, hi: 0 };
+            Cent modulus;
+            bufStart = buf.length;
+            do
+            {
+                uint x = void;
+                if (ugt(radix, val))
+                {
+                    x = cast(uint) val.lo;
+                    val = Cent(0, 0);
+                }
+                else
+                {
+                    val = udivmod(val, radix, modulus);
+                    x = cast(uint) modulus.lo;
+                }
+                buf[--bufStart] = cast(Char) ('0' + x);
+            } while (tst(val));
+            if (isNeg)
+                signChar = '-';
+            else if (fmt.flPlus)
+                signChar = '+';
+            else if (fmt.flSpace)
+                signChar = ' ';
+        }
+        else if (fmt.spec == 'x' || fmt.spec == 'X')
+        {
+            immutable hexDigits = fmt.spec == 'X' ? "0123456789ABCDEF" : "0123456789abcdef";
+            ulong a = data.lo;
+            bufStart = buf.length - 1;
+            size_t penPos = buf.length - 1;
+            do
+            {
+                if ((buf[penPos] = hexDigits[0xF & cast(uint) a]) != '0')
+                    bufStart = penPos;
+                a >>>= 4;
+            } while (--penPos >= buf.length - 16);
+            a = data.hi;
+            do
+            {
+                if ((buf[penPos] = hexDigits[0xF & cast(uint) a]) != '0')
+                    bufStart = penPos;
+                a >>>= 4;
+            } while (--penPos >= buf.length - 32);
+        }
+        else
+        {
+            throw new FormatException("Format specifier not understood: %" ~ fmt.spec);
+        }
+
+        const minw = (buf.length - bufStart) + int(signChar != 0);
+        const maxw = minw < fmt.width ? fmt.width : minw;
+        const difw = maxw - minw;
+
+        static void putRepeatedChars(Char c)(scope ref Writer sink, size_t n)
+        {
+            static immutable Char[8] array = [c, c, c, c, c, c, c, c];
+            foreach (_; 0 .. n / 8)
+                put(sink, array[0 .. 8]);
+            if (n & 7)
+                put(sink, array[0 .. n & 7]);
+        }
+
+        if (!fmt.flDash && !fmt.flZero && difw)
+            putRepeatedChars!' '(sink, difw);
+
+        if (signChar)
+        {
+            Char[1] signCharBuf = signChar;
+            put(sink, signCharBuf[0 .. 1]);
+        }
+
+        if (!fmt.flDash && fmt.flZero && difw)
+            putRepeatedChars!'0'(sink, difw);
+
+        put(sink, buf[bufStart .. $]);
+
+        if (fmt.flDash && difw)
+            putRepeatedChars!' '(sink, difw);
+    }
+
+    /**
+        `toString` is rarely directly invoked; the usual way of using it is via
+        $(REF format, std, format):
+     */
+    @safe unittest
+    {
+        import std.format : format;
+
+        assert(format("%s", Int128.max) == "170141183460469231731687303715884105727");
+        assert(format("%s", Int128.min) == "-170141183460469231731687303715884105728");
+        assert(format("%x", Int128.max) == "7fffffffffffffffffffffffffffffff");
+        assert(format("%X", Int128.max) == "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
+        assert(format("%032X", Int128(123L)) == "0000000000000000000000000000007B");
+        assert(format("%+ 40d", Int128(123L)) == "                                    +123");
+        assert(format("%+-40d", Int128(123L)) == "+123                                    ");
+    }
+
+    /// Also can format as `wchar` or `dchar`.
+    @safe unittest
+    {
+        import std.conv : to;
+
+        assert(to!wstring(Int128.max) == "170141183460469231731687303715884105727"w);
+        assert(to!dstring(Int128.max) == "170141183460469231731687303715884105727"d);
     }
 
     enum min = Int128(long.min, 0);             /// minimum value
@@ -372,3 +551,59 @@ unittest
     c = Int128(-1L);
     assert(c == -1L);
 }
+
+@system unittest
+{
+    alias Seq(T...) = T;
+    Int128 c = Int128(-1L);
+    assert(c.opCmp(-1L) == 0);
+    // To avoid regression calling opCmp with any integral type needs to
+    // work without the compiler complaining "opCmp called with argument
+    // X matches both <...>".
+    static foreach (Int; Seq!(long, int, short, byte, ulong, uint, ushort, ubyte, dchar, wchar, char))
+        assert(c < Int.max);
+    static foreach (Int; Seq!(int, short, byte))
+        assert(c.opCmp(Int(-1)) == 0);
+    assert(c < true);
+    // To avoid regression calling opCmp with any type that converts to an
+    // integral type through alias this needs to work regardless of whether
+    // the alias is safe/pure/nothrow/nogc and regardless of whether the
+    // type has a disabled postblit.
+    static struct Wrapped(T)
+    {
+        T value;
+        uint count;
+        T get() @system { ++count; return value; } // not const
+        alias get this;
+        @disable this(this); // no implicit copies
+    }
+    assert(c.opCmp(Wrapped!long(-1)) == 0);
+    auto w = Wrapped!ulong(ulong.max);
+    w.count++; // avoid invalid D-Scanner message that w could have been declared const
+    assert(c < w);
+
+    const zero = Int128(0L);
+    const one = Int128(1L);
+    const neg_one = Int128(-1L);
+    const neg_two = Int128(-2L);
+    // Correct result with ulong.max:
+    assert(zero + ulong.max == ulong.max);
+    assert(one * ulong.max == ulong.max);
+    assert((neg_one & ulong.max) == ulong.max);
+    assert((zero | ulong.max) == ulong.max);
+    assert((zero ^ ulong.max) == ulong.max);
+    // Correct result with negative arguments:
+    assert(zero + -1L == -1L);
+    assert(neg_two * -3L == 6L);
+    assert(neg_two / -2L == 1L);
+    assert(neg_two % -2L == 0L);
+    assert((neg_one & -1L) == -1L);
+    assert((zero | -1L) == -1L);
+    assert((zero ^ -1L) == -1L);
+    // Ensure alias this still works.
+    {
+        Int128 a = zero;
+        assert((a ^= w) == ulong.max);
+    }
+    assert((Wrapped!long(-1L) + zero) == -1L);
+}
diff --git a/libphobos/src/std/json.d b/libphobos/src/std/json.d
index 7d48890501f..6e94a5d71ce 100644
--- a/libphobos/src/std/json.d
+++ b/libphobos/src/std/json.d
@@ -70,25 +70,25 @@ String literals used to represent special float values within JSON strings.
 */
 enum JSONFloatLiteral : string
 {
-    nan         = "NaN",       /// string representation of floating-point NaN
-    inf         = "Infinite",  /// string representation of floating-point Infinity
-    negativeInf = "-Infinite", /// string representation of floating-point negative Infinity
+    nan         = "NaN",       /// String representation of floating-point NaN
+    inf         = "Infinite",  /// String representation of floating-point Infinity
+    negativeInf = "-Infinite", /// String representation of floating-point negative Infinity
 }
 
 /**
-Flags that control how json is encoded and parsed.
+Flags that control how JSON is encoded and parsed.
 */
 enum JSONOptions
 {
-    none,                       /// standard parsing
-    specialFloatLiterals = 0x1, /// encode NaN and Inf float values as strings
-    escapeNonAsciiChars = 0x2,  /// encode non ascii characters with an unicode escape sequence
-    doNotEscapeSlashes = 0x4,   /// do not escape slashes ('/')
+    none,                       /// Standard parsing and encoding
+    specialFloatLiterals = 0x1, /// Encode NaN and Inf float values as strings
+    escapeNonAsciiChars = 0x2,  /// Encode non-ASCII characters with a Unicode escape sequence
+    doNotEscapeSlashes = 0x4,   /// Do not escape slashes ('/')
     strictParsing = 0x8,        /// Strictly follow RFC-8259 grammar when parsing
 }
 
 /**
-JSON type enumeration
+Enumeration of JSON types
 */
 enum JSONType : byte
 {
@@ -275,7 +275,7 @@ struct JSONValue
      * Value getter/setter for `JSONType.object`.
      * Throws: `JSONException` for read access if `type` is not
      * `JSONType.object`.
-     * Note: this is @system because of the following pattern:
+     * Note: This is @system because of the following pattern:
        ---
        auto a = &(json.object());
        json.uinteger = 0;        // overwrite AA pointer
@@ -297,9 +297,11 @@ struct JSONValue
 
     /***
      * Value getter for `JSONType.object`.
-     * Unlike `object`, this retrieves the object by value and can be used in @safe code.
+     * Unlike `object`, this retrieves the object by value
+     * and can be used in @safe code.
      *
-     * A caveat is that, if the returned value is null, modifications will not be visible:
+     * One possible caveat is that, if the returned value is null,
+     * modifications will not be visible:
      * ---
      * JSONValue json;
      * json.object = null;
@@ -321,7 +323,7 @@ struct JSONValue
      * Value getter/setter for `JSONType.array`.
      * Throws: `JSONException` for read access if `type` is not
      * `JSONType.array`.
-     * Note: this is @system because of the following pattern:
+     * Note: This is @system because of the following pattern:
        ---
        auto a = &(json.array());
        json.uinteger = 0;  // overwrite array pointer
@@ -345,8 +347,8 @@ struct JSONValue
      * Value getter for `JSONType.array`.
      * Unlike `array`, this retrieves the array by value and can be used in @safe code.
      *
-     * A caveat is that, if you append to the returned array, the new values aren't visible in the
-     * JSONValue:
+     * One possible caveat is that, if you append to the returned array,
+     * the new values aren't visible in the `JSONValue`:
      * ---
      * JSONValue json;
      * json.array = [JSONValue("hello")];
@@ -371,9 +373,8 @@ struct JSONValue
     }
 
     /***
-     * Generic type value getter
      * A convenience getter that returns this `JSONValue` as the specified D type.
-     * Note: only numeric, `bool`, `string`, `JSONValue[string]` and `JSONValue[]` types are accepted
+     * Note: Only numeric types, `bool`, `string`, `JSONValue[string]`, and `JSONValue[]` types are accepted
      * Throws: `JSONException` if `T` cannot hold the contents of this `JSONValue`
      *         `ConvException` in case of integer overflow when converting to `T`
      */
@@ -659,7 +660,7 @@ struct JSONValue
     }
 
     /***
-     * Array syntax for json arrays.
+     * Array syntax for JSON arrays.
      * Throws: `JSONException` if `type` is not `JSONType.array`.
      */
     ref inout(JSONValue) opIndex(size_t i) inout pure @safe
@@ -678,7 +679,7 @@ struct JSONValue
     }
 
     /***
-     * Hash syntax for json objects.
+     * Hash syntax for JSON objects.
      * Throws: `JSONException` if `type` is not `JSONType.object`.
      */
     ref inout(JSONValue) opIndex(return scope string k) inout pure @safe
@@ -695,10 +696,12 @@ struct JSONValue
     }
 
     /***
-     * Operator sets `value` for element of JSON object by `key`.
+     * Provides support for index assignments, which sets the
+     * corresponding value of the JSON object's `key` field to `value`.
      *
-     * If JSON value is null, then operator initializes it with object and then
-     * sets `value` for it.
+     * If the `JSONValue` is `JSONType.null_`, then this function
+     * initializes it with a JSON object and then performs
+     * the index assignment.
      *
      * Throws: `JSONException` if `type` is not `JSONType.object`
      * or `JSONType.null_`.
@@ -777,12 +780,12 @@ struct JSONValue
     }
 
     /**
-     * Support for the `in` operator.
+     * Provides support for the `in` operator.
      *
-     * Tests wether a key can be found in an object.
+     * Tests whether a key can be found in an object.
      *
      * Returns:
-     *      when found, the `inout(JSONValue)*` that matches to the key,
+     *      When found, the `inout(JSONValue)*` that matches to the key,
      *      otherwise `null`.
      *
      * Throws: `JSONException` if the right hand side argument `JSONType`
diff --git a/libphobos/src/std/math/package.d b/libphobos/src/std/math/package.d
index b5f914acf7c..614f4d36fbb 100644
--- a/libphobos/src/std/math/package.d
+++ b/libphobos/src/std/math/package.d
@@ -3,7 +3,7 @@
 /**
  * Contains the elementary mathematical functions (powers, roots,
  * and trigonometric functions), and low-level floating-point operations.
- * Mathematical special functions are available in `std.mathspecial`.
+ * Mathematical special functions are available in $(MREF std, mathspecial).
  *
 $(SCRIPT inhibitQuickIndex = 1;)
 
diff --git a/libphobos/src/std/range/package.d b/libphobos/src/std/range/package.d
index 191ec32cf4b..1b4f233d94a 100644
--- a/libphobos/src/std/range/package.d
+++ b/libphobos/src/std/range/package.d
@@ -1384,7 +1384,7 @@ if (Ranges.length > 0 &&
                     // force staticMap type conversion to Rebindable
                     static struct ResultRanges
                     {
-                        staticMap!(Rebindable, Ranges) fields;
+                        staticMap!(Rebindable, typeof(source)) fields;
                     }
                     auto sourceI(size_t i)() => rebindable(this.source[i]);
                     auto resultRanges = ResultRanges(staticMap!(sourceI, aliasSeqOf!(R.length.iota))).fields;
@@ -1672,6 +1672,17 @@ pure @safe unittest
     assert(range.array == [S(5), S(6)]);
 }
 
+/// https://issues.dlang.org/show_bug.cgi?id=24064
+pure @safe nothrow unittest
+{
+    import std.algorithm.comparison : equal;
+    import std.typecons : Nullable;
+
+    immutable Nullable!string foo = "b";
+    string[] bar = ["a"];
+    assert(chain(bar, foo).equal(["a", "b"]));
+}
+
 pure @safe nothrow @nogc unittest
 {
     // support non-copyable items
diff --git a/libphobos/src/std/regex/internal/ir.d b/libphobos/src/std/regex/internal/ir.d
index 3b38f9c9fbc..069d75f8822 100644
--- a/libphobos/src/std/regex/internal/ir.d
+++ b/libphobos/src/std/regex/internal/ir.d
@@ -1045,7 +1045,7 @@ if (!hasElaborateDestructor!T)
         return isBig ? big.ptr[0 .. length] : small[0 .. length];
     }
 
-    this(this)
+    this(this) @trusted
     {
         if (isBig)
         {
diff --git a/libphobos/src/std/socket.d b/libphobos/src/std/socket.d
index 3359c8ebf62..4052479f9ca 100644
--- a/libphobos/src/std/socket.d
+++ b/libphobos/src/std/socket.d
@@ -181,16 +181,13 @@ string formatSocketError(int err) @trusted
         return "Socket error " ~ to!string(err);
 }
 
-/// Retrieve the error message for the most recently encountered network error.
+/// Returns the error message of the most recently encountered network error.
 @property string lastSocketError()
 {
     return formatSocketError(_lasterr());
 }
 
-/**
- * Socket exceptions representing network errors reported by the operating
- * system.
- */
+/// Socket exception representing network errors reported by the operating system.
 class SocketOSException: SocketException
 {
     int errorCode;     /// Platform-specific error code.
@@ -234,14 +231,14 @@ class SocketOSException: SocketException
     }
 }
 
-/// Socket exceptions representing invalid parameters specified by user code.
+/// Socket exception representing invalid parameters specified by user code.
 class SocketParameterException: SocketException
 {
     mixin basicExceptionCtors;
 }
 
 /**
- * Socket exceptions representing attempts to use network capabilities not
+ * Socket exception representing attempts to use network capabilities not
  * available on the current system.
  */
 class SocketFeatureException: SocketException
@@ -254,7 +251,7 @@ class SocketFeatureException: SocketException
  * Returns:
  * `true` if the last socket operation failed because the socket
  * was in non-blocking mode and the operation would have blocked,
- * or if the socket is in blocking mode and set a SNDTIMEO or RCVTIMEO,
+ * or if the socket is in blocking mode and set a `SNDTIMEO` or `RCVTIMEO`,
  * and the operation timed out.
  */
 bool wouldHaveBlocked() nothrow @nogc
@@ -334,7 +331,7 @@ shared static ~this() @system nothrow @nogc
 enum AddressFamily: ushort
 {
     UNSPEC =     AF_UNSPEC,     /// Unspecified address family
-    UNIX =       AF_UNIX,       /// Local communication
+    UNIX =       AF_UNIX,       /// Local communication (Unix socket)
     INET =       AF_INET,       /// Internet Protocol version 4
     IPX =        AF_IPX,        /// Novell IPX
     APPLETALK =  AF_APPLETALK,  /// AppleTalk
@@ -374,7 +371,7 @@ enum ProtocolType: int
 
 
 /**
- * `Protocol` is a class for retrieving protocol information.
+ * Class for retrieving protocol information.
  *
  * Example:
  * ---
@@ -473,7 +470,7 @@ version (CRuntime_Bionic) {} else
 
 
 /**
- * `Service` is a class for retrieving service information.
+ * Class for retrieving service information.
  *
  * Example:
  * ---
@@ -618,7 +615,7 @@ class HostException: SocketOSException
 }
 
 /**
- * `InternetHost` is a class for resolving IPv4 addresses.
+ * Class for resolving IPv4 addresses.
  *
  * Consider using `getAddress`, `parseAddress` and `Address` methods
  * instead of using this class directly.
@@ -1220,7 +1217,7 @@ class AddressException: SocketOSException
 
 
 /**
- * `Address` is an abstract class for representing a socket addresses.
+ * Abstract class for representing a socket address.
  *
  * Example:
  * ---
@@ -1402,7 +1399,7 @@ abstract class Address
 }
 
 /**
- * `UnknownAddress` encapsulates an unknown socket address.
+ * Encapsulates an unknown socket address.
  */
 class UnknownAddress: Address
 {
@@ -1431,7 +1428,7 @@ public:
 
 
 /**
- * `UnknownAddressReference` encapsulates a reference to an arbitrary
+ * Encapsulates a reference to an arbitrary
  * socket address.
  */
 class UnknownAddressReference: Address
@@ -1474,8 +1471,7 @@ public:
 
 
 /**
- * `InternetAddress` encapsulates an IPv4 (Internet Protocol version 4)
- * socket address.
+ * Encapsulates an IPv4 (Internet Protocol version 4) socket address.
  *
  * Consider using `getAddress`, `parseAddress` and `Address` methods
  * instead of using this class directly.
@@ -1624,7 +1620,8 @@ public:
     }
 
     /**
-     * Compares with another InternetAddress of same type for equality
+     * Provides support for comparing equality with another
+     * InternetAddress of the same type.
      * Returns: true if the InternetAddresses share the same address and
      * port number.
      */
@@ -1728,8 +1725,7 @@ public:
 
 
 /**
- * `Internet6Address` encapsulates an IPv6 (Internet Protocol version 6)
- * socket address.
+ * Encapsulates an IPv6 (Internet Protocol version 6) socket address.
  *
  * Consider using `getAddress`, `parseAddress` and `Address` methods
  * instead of using this class directly.
@@ -1913,8 +1909,8 @@ version (StdDdoc)
     }
 
     /**
-     * `UnixAddress` encapsulates an address for a Unix domain socket
-     * (`AF_UNIX`), i.e. a socket bound to a path name in the file system.
+     * Encapsulates an address for a Unix domain socket (`AF_UNIX`),
+     * i.e. a socket bound to a path name in the file system.
      * Available only on supported systems.
      *
      * Linux also supports an abstract address namespace, in which addresses
@@ -2111,7 +2107,7 @@ static if (is(sockaddr_un))
 
 
 /**
- * Class for exceptions thrown by `Socket.accept`.
+ * Exception thrown by `Socket.accept`.
  */
 class SocketAcceptException: SocketOSException
 {
@@ -2127,7 +2123,7 @@ enum SocketShutdown: int
 }
 
 
-/// Flags may be OR'ed together:
+/// Socket flags that may be OR'ed together:
 enum SocketFlags: int
 {
     NONE =       0,                 /// no flags specified
@@ -2622,7 +2618,7 @@ enum SocketOption: int
 
 
 /**
- * `Socket` is a class that creates a network communication endpoint using
+ * Class that creates a network communication endpoint using
  * the Berkeley sockets interface.
  */
 class Socket
@@ -2969,7 +2965,7 @@ public:
 
 
     /**
-     * Returns: the local machine's host name
+     * Returns: The local machine's host name
      */
     static @property string hostName() @trusted     // getter
     {
@@ -3518,7 +3514,7 @@ public:
 
     /**
      * Can be overridden to support other addresses.
-     * Returns: a new `Address` object for the current address family.
+     * Returns: A new `Address` object for the current address family.
      */
     protected Address createAddress() pure nothrow
     {
@@ -3549,7 +3545,7 @@ public:
 }
 
 
-/// `TcpSocket` is a shortcut class for a TCP Socket.
+/// Shortcut class for a TCP Socket.
 class TcpSocket: Socket
 {
     /// Constructs a blocking TCP Socket.
@@ -3566,7 +3562,7 @@ class TcpSocket: Socket
 
 
     //shortcut
-    /// Constructs a blocking TCP Socket and connects to an `Address`.
+    /// Constructs a blocking TCP Socket and connects to the given `Address`.
     this(Address connectTo)
     {
         this(connectTo.addressFamily);
@@ -3575,7 +3571,7 @@ class TcpSocket: Socket
 }
 
 
-/// `UdpSocket` is a shortcut class for a UDP Socket.
+/// Shortcut class for a UDP Socket.
 class UdpSocket: Socket
 {
     /// Constructs a blocking UDP Socket.
diff --git a/libphobos/src/std/stdio.d b/libphobos/src/std/stdio.d
index d9291b11bde..40dc85420fe 100644
--- a/libphobos/src/std/stdio.d
+++ b/libphobos/src/std/stdio.d
@@ -122,17 +122,12 @@ alias KeepTerminator = Flag!"keepTerminator";
 
 version (CRuntime_Microsoft)
 {
-    version = MICROSOFT_STDIO;
 }
 else version (CRuntime_DigitalMars)
 {
-    // Specific to the way Digital Mars C does stdio
-    version = DIGITAL_MARS_STDIO;
 }
 else version (CRuntime_Glibc)
 {
-    // Specific to the way Gnu C does stdio
-    version = GCC_IO;
 }
 else version (CRuntime_Bionic)
 {
@@ -220,7 +215,7 @@ version (Posix)
     static import core.sys.posix.stdio; // getdelim, flockfile
 }
 
-version (DIGITAL_MARS_STDIO)
+version (CRuntime_DigitalMars)
 {
     private alias _FPUTC = _fputc_nlock;
     private alias _FPUTWC = _fputwc_nlock;
@@ -229,7 +224,7 @@ version (DIGITAL_MARS_STDIO)
     private alias _FLOCK = __fp_lock;
     private alias _FUNLOCK = __fp_unlock;
 
-    // Alias for MICROSOFT_STDIO compatibility.
+    // Alias for CRuntime_Microsoft compatibility.
     // @@@DEPRECATED_2.107@@@
     // Rename this back to _setmode once the deprecation phase has ended.
     private alias __setmode = setmode;
@@ -267,7 +262,7 @@ version (DIGITAL_MARS_STDIO)
                ~ "std.stdio and will be removed afer 2.107")
     fileno_t _fileno(FILE* f) { return f._file; }
 }
-else version (MICROSOFT_STDIO)
+else version (CRuntime_Microsoft)
 {
     private alias _FPUTC = _fputc_nolock;
     private alias _FPUTWC = _fputwc_nolock;
@@ -277,7 +272,7 @@ else version (MICROSOFT_STDIO)
     private alias _FUNLOCK = _unlock_file;
 
     // @@@DEPRECATED_2.107@@@
-    // Remove this once the deprecation phase for DIGITAL_MARS_STDIO has ended.
+    // Remove this once the deprecation phase for CRuntime_DigitalMars has ended.
     private alias __setmode = _setmode;
 
     // @@@DEPRECATED_2.107@@@
@@ -305,7 +300,7 @@ else version (MICROSOFT_STDIO)
                ~ "std.stdio and will be removed afer 2.107")
     alias FUNLOCK = _unlock_file;
 }
-else version (GCC_IO)
+else version (CRuntime_Glibc)
 {
     private alias _FPUTC = fputc_unlocked;
     private alias _FPUTWC = fputwc_unlocked;
@@ -419,7 +414,7 @@ private extern (C) @nogc nothrow
 {
     pragma(mangle, _FPUTC.mangleof) int trustedFPUTC(int ch, _iobuf* h) @trusted;
 
-    version (DIGITAL_MARS_STDIO)
+    version (CRuntime_DigitalMars)
         pragma(mangle, _FPUTWC.mangleof) int trustedFPUTWC(int ch, _iobuf* h) @trusted;
     else
         pragma(mangle, _FPUTWC.mangleof) int trustedFPUTWC(wchar_t ch, _iobuf* h) @trusted;
@@ -598,7 +593,7 @@ Throws: `ErrnoException` if the file could not be opened.
                 name);
 
         // MSVCRT workaround (https://issues.dlang.org/show_bug.cgi?id=14422)
-        version (MICROSOFT_STDIO)
+        version (CRuntime_Microsoft)
         {
             setAppendWin(stdioOpenmode);
         }
@@ -726,7 +721,7 @@ Throws: `ErrnoException` in case of error.
         }
         _p = cast(Impl*) enforce(malloc(Impl.sizeof), "Out of memory");
         initImpl(handle, name, 1, isPopened);
-        version (MICROSOFT_STDIO)
+        version (CRuntime_Microsoft)
         {
             setAppendWin(stdioOpenmode);
         }
@@ -761,7 +756,7 @@ Throws: `ErrnoException` in case of error.
         }
     }
 
-    version (MICROSOFT_STDIO)
+    version (CRuntime_Microsoft)
     {
         private void setAppendWin(scope const(char)[] stdioOpenmode) @safe
         {
@@ -894,7 +889,7 @@ Params:
         auto modez = stdioOpenmode.tempCString();
         detach();
 
-        version (DIGITAL_MARS_STDIO)
+        version (CRuntime_DigitalMars)
         {
             // This is a re-implementation of DMC's fdopen, but without the
             // mucking with the file descriptor.  POSIX standard requires the
@@ -909,17 +904,20 @@ Params:
             iob._flag &= ~_IOTRAN;
             _FUNLOCK(fp);
         }
-        else
+        else version (CRuntime_Microsoft)
         {
-            version (Windows) // MSVCRT
-                auto fp = _fdopen(fd, modez);
-            else version (Posix)
-            {
-                import core.sys.posix.stdio : fdopen;
-                auto fp = fdopen(fd, modez);
-            }
+            auto fp = _fdopen(fd, modez);
             errnoEnforce(fp);
         }
+        else version (Posix)
+        {
+            import core.sys.posix.stdio : fdopen;
+            auto fp = fdopen(fd, modez);
+            errnoEnforce(fp);
+        }
+        else
+            static assert(0, "no fdopen() available");
+
         this = File(fp, name);
     }
 
@@ -945,7 +943,7 @@ Throws: `ErrnoException` in case of error.
         import std.format : format;
 
         // Create file descriptors from the handles
-        version (DIGITAL_MARS_STDIO)
+        version (CRuntime_DigitalMars)
             auto fd = _handleToFD(handle, FHND_DEVICE);
         else // MSVCRT
         {
@@ -1190,7 +1188,7 @@ Throws: `ErrnoException` if the file is not opened or the call to `fread` fails.
             immutable fileno_t fd = .fileno(_p.handle);
             immutable mode = .__setmode(fd, _O_BINARY);
             scope(exit) .__setmode(fd, mode);
-            version (DIGITAL_MARS_STDIO)
+            version (CRuntime_DigitalMars)
             {
                 import core.atomic : atomicOp;
 
@@ -1288,7 +1286,7 @@ Throws: `ErrnoException` if the file is not opened or if the call to `fwrite` fa
                 .__setmode(fd, _O_BINARY);
             }
 
-            version (DIGITAL_MARS_STDIO)
+            version (CRuntime_DigitalMars)
             {
                 import core.atomic : atomicOp;
 
@@ -2351,7 +2349,7 @@ Returns the underlying operating system `HANDLE` (Windows only).
     version (Windows)
     @property HANDLE windowsHandle()
     {
-        version (DIGITAL_MARS_STDIO)
+        version (CRuntime_DigitalMars)
             return _fdToHandle(fileno);
         else
             return cast(HANDLE)_get_osfhandle(fileno);
@@ -3147,7 +3145,7 @@ is empty, throws an `Exception`. In case of an I/O error throws
             file_ = f;
             FILE* fps = f._p.handle;
 
-            version (MICROSOFT_STDIO)
+            version (CRuntime_Microsoft)
             {
                 // Microsoft doesn't implement fwide. Instead, there's the
                 // concept of ANSI/UNICODE mode. fputc doesn't work in UNICODE
@@ -3388,7 +3386,7 @@ is empty, throws an `Exception`. In case of an I/O error throws
         {
             fileno_t fd;
             int oldMode;
-            version (DIGITAL_MARS_STDIO)
+            version (CRuntime_DigitalMars)
                 ubyte oldInfo;
         }
 
@@ -3410,7 +3408,7 @@ is empty, throws an `Exception`. In case of an I/O error throws
                 .fflush(fps); // before changing translation mode
                 fd = .fileno(fps);
                 oldMode = .__setmode(fd, _O_BINARY);
-                version (DIGITAL_MARS_STDIO)
+                version (CRuntime_DigitalMars)
                 {
                     import core.atomic : atomicOp;
 
@@ -3431,7 +3429,7 @@ is empty, throws an `Exception`. In case of an I/O error throws
             version (Windows)
             {
                 .fflush(fps); // before restoring translation mode
-                version (DIGITAL_MARS_STDIO)
+                version (CRuntime_DigitalMars)
                 {
                     // https://issues.dlang.org/show_bug.cgi?id=4243
                     __fhnd_info[fd] = oldInfo;
@@ -3889,7 +3887,7 @@ void main()
         return setlocale(LC_CTYPE, loc.ptr).fromStringz.endsWith(loc);
     });
     scope(exit) () @trusted { setlocale(LC_CTYPE, oldCt); } ();
-    version (DIGITAL_MARS_STDIO) // DM can't handle Unicode above U+07FF.
+    version (CRuntime_DigitalMars) // DM can't handle Unicode above U+07FF.
     {
         alias strs = AliasSeq!("xä\u07FE", "yö\u07FF"w);
     }
@@ -3899,7 +3897,7 @@ void main()
     }
     {
         auto f = File(deleteme, "w");
-        version (MICROSOFT_STDIO)
+        version (CRuntime_Microsoft)
         {
             () @trusted { __setmode(fileno(f.getFP()), _O_U8TEXT); } ();
         }
@@ -5539,7 +5537,7 @@ private struct LockedFile
 // Private implementation of readln
 private size_t readlnImpl(FILE* fps, ref char[] buf, dchar terminator, File.Orientation orientation) @safe
 {
-    version (DIGITAL_MARS_STDIO)
+    version (CRuntime_DigitalMars)
     return () @trusted {
         auto lf = LockedFile(fps);
         ReadlnAppender app;
@@ -5652,7 +5650,7 @@ private size_t readlnImpl(FILE* fps, ref char[] buf, dchar terminator, File.Orie
         buf = app.data;
         return buf.length;
     }();
-    else version (MICROSOFT_STDIO)
+    else version (CRuntime_Microsoft)
     {
         auto lf = LockedFile(fps);
 
diff --git a/libphobos/src/std/traits.d b/libphobos/src/std/traits.d
index 4dc569df297..2ed7ee527b0 100644
--- a/libphobos/src/std/traits.d
+++ b/libphobos/src/std/traits.d
@@ -1125,7 +1125,7 @@ if (isCallable!func && variadicFunctionStyle!func == Variadic.no)
 }
 
 /**
-Get tuple, one per function parameter, of the storage classes of the parameters.
+Get a tuple of the storage classes of a function's parameters.
 Params:
     func = function symbol or type of function, delegate, or pointer to function
 Returns:
@@ -1154,22 +1154,16 @@ if (isCallable!func)
 
     static if (is(Func PT == __parameters))
     {
-        template StorageClass(size_t i)
+        alias ParameterStorageClassTuple = AliasSeq!();
+        static foreach (i; 0 .. PT.length)
         {
-            static if (i < PT.length)
-            {
-                alias StorageClass = AliasSeq!(
-                        extractParameterStorageClassFlags!(__traits(getParameterStorageClasses, Func, i)),
-                        StorageClass!(i + 1));
-            }
-            else
-                alias StorageClass = AliasSeq!();
+            ParameterStorageClassTuple = AliasSeq!(ParameterStorageClassTuple,
+                extractParameterStorageClassFlags!(__traits(getParameterStorageClasses, Func, i)));
         }
-        alias ParameterStorageClassTuple = StorageClass!0;
     }
     else
     {
-        static assert(0, func[0].stringof ~ " is not a function");
+        static assert(0, func.stringof, " is not a function");
         alias ParameterStorageClassTuple = AliasSeq!();
     }
 }
@@ -1317,7 +1311,8 @@ if (isCallable!func)
 {
     static if (is(FunctionTypeOf!func PT == __parameters))
     {
-        template Get(size_t i)
+        alias ParameterIdentifierTuple = AliasSeq!();
+        static foreach (i; 0 .. PT.length)
         {
             static if (!isFunctionPointer!func && !isDelegate!func
                        // Unnamed parameters yield CT error.
@@ -1325,32 +1320,21 @@ if (isCallable!func)
                        // Filter out unnamed args, which look like (Type) instead of (Type name).
                        && PT[i].stringof != PT[i .. i+1].stringof[1..$-1])
             {
-                enum Get = __traits(identifier, PT[i .. i+1]);
+                ParameterIdentifierTuple = AliasSeq!(ParameterIdentifierTuple,
+                    __traits(identifier, PT[i .. i+1]));
             }
             else
             {
-                enum Get = "";
+                ParameterIdentifierTuple = AliasSeq!(ParameterIdentifierTuple, "");
             }
         }
     }
     else
     {
         static assert(0, func.stringof ~ " is not a function");
-
-        // Define dummy entities to avoid pointless errors
-        template Get(size_t i) { enum Get = ""; }
-        alias PT = AliasSeq!();
-    }
-
-    template Impl(size_t i = 0)
-    {
-        static if (i == PT.length)
-            alias Impl = AliasSeq!();
-        else
-            alias Impl = AliasSeq!(Get!i, Impl!(i+1));
+        // avoid pointless errors
+        alias ParameterIdentifierTuple = AliasSeq!();
     }
-
-    alias ParameterIdentifierTuple = Impl!();
 }
 
 ///
@@ -1408,7 +1392,7 @@ if (isCallable!func)
 
 
 /**
-Get, as a tuple, the default value of the parameters to a function symbol.
+Get, as a tuple, the default values of the parameters to a function symbol.
 If a parameter doesn't have the default value, `void` is returned instead.
  */
 template ParameterDefaults(alias func)
@@ -1426,48 +1410,36 @@ if (isCallable!func)
             enum args = "args" ~ (name == "args" ? "_" : "");
             enum val = "val" ~ (name == "val" ? "_" : "");
             enum ptr = "ptr" ~ (name == "ptr" ? "_" : "");
-            mixin("
-                enum hasDefaultArg = (PT[i .. i+1] " ~ args ~ ") { return true; };
-            ");
+            enum hasDefaultArg = mixin("(PT[i .. i+1] ", args, ") => true");
             static if (is(typeof(hasDefaultArg())))
             {
-                mixin("
-                // workaround scope escape check, see
-                // https://issues.dlang.org/show_bug.cgi?id=16582
-                // should use return scope once available
-                enum get = (PT[i .. i+1] " ~ args ~ ") @trusted
+                enum get = mixin("(return scope PT[i .. i+1] ", args, ")
                 {
                     // If the parameter is lazy, we force it to be evaluated
                     // like this.
-                    auto " ~ val ~ " = " ~ args ~ "[0];
-                    auto " ~ ptr ~ " = &" ~ val ~ ";
-                    return *" ~ ptr ~ ";
-                };");
+                    auto ", val, " = ", args, "[0];
+                    auto ", ptr, " = &", val, ";
+                    return *", ptr, ";
+                }");
                 enum Get = get();
             }
             else
                 alias Get = void;
                 // If default arg doesn't exist, returns void instead.
         }
+        alias ParameterDefaults = AliasSeq!();
+        static foreach (i; 0 .. PT.length)
+        {
+            ParameterDefaults = AliasSeq!(ParameterDefaults,
+                Get!i);
+        }
     }
     else
     {
         static assert(0, func.stringof ~ " is not a function");
-
-        // Define dummy entities to avoid pointless errors
-        template Get(size_t i) { enum Get = ""; }
-        alias PT = AliasSeq!();
+        // avoid pointless errors
+        alias ParameterDefaults = AliasSeq!();
     }
-
-    template Impl(size_t i = 0)
-    {
-        static if (i == PT.length)
-            alias Impl = AliasSeq!();
-        else
-            alias Impl = AliasSeq!(Get!i, Impl!(i+1));
-    }
-
-    alias ParameterDefaults = Impl!();
 }
 
 ///
diff --git a/libphobos/src/std/uni/package.d b/libphobos/src/std/uni/package.d
index 6ab6ba0f631..9903d6c28c3 100644
--- a/libphobos/src/std/uni/package.d
+++ b/libphobos/src/std/uni/package.d
@@ -7697,6 +7697,15 @@ public:
             static assert(false, "No operation "~op~" defined for Grapheme");
     }
 
+    // This is not a good `opEquals`, but formerly the automatically generated
+    // opEquals was used, which was inferred `@safe` because of bugzilla 20655:
+    // https://issues.dlang.org/show_bug.cgi?id=20655
+    // This `@trusted opEquals` is only here to prevent breakage.
+    bool opEquals(R)(const auto ref R other) const @trusted
+    {
+        return this.tupleof == other.tupleof;
+    }
+
     /++
         True if this object contains valid extended grapheme cluster.
         Decoding primitives of this module always return a valid `Grapheme`.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-23 11:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-23 11:01 [gcc r14-4237] d: Merge upstream dmd, druntime 4574d1728d, phobos d7e79f024 Iain Buclaw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).