From 019e2bbe66a7687bec138aba4b7ba6b9c1f938c8 Mon Sep 17 00:00:00 2001 From: Geod24 Date: Thu, 5 Nov 2020 18:02:21 +0900 Subject: [PATCH] Enable -checkaction=context by default --- changelog/checkaction-context-default.dd | 15 +++++++++++++++ src/dmd/frontend.h | 8 ++++---- src/dmd/globals.d | 5 +++-- src/dmd/globals.h | 4 ++-- test/runnable/complex.d | 2 +- test/runnable/iasm.d | 1 + test/runnable/iasm64.d | 2 +- 7 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 changelog/checkaction-context-default.dd diff --git a/changelog/checkaction-context-default.dd b/changelog/checkaction-context-default.dd new file mode 100644 index 000000000000..54bfce3275ee --- /dev/null +++ b/changelog/checkaction-context-default.dd @@ -0,0 +1,15 @@ +Enhanced `assert` informations are now printed by default + +Starting from this release, DMD will now print rich informations on assert failures. +For example, the following code: +--- +void main () +{ + int a = 0, b = 42; + assert(a == b); +} +--- + +Will now print: `core.exception.AssertError@filename.d(4): 0 != 42`. +This behavior was previously accessible via the CLI switch `-checkaction=context`. +To revert to the old behavior, use `-checkaction=D`. diff --git a/src/dmd/frontend.h b/src/dmd/frontend.h index 1a91c7af7830..da8d7d825e15 100644 --- a/src/dmd/frontend.h +++ b/src/dmd/frontend.h @@ -376,10 +376,10 @@ enum class CHECKENABLE : uint8_t enum class CHECKACTION : uint8_t { - D = 0u, - C = 1u, - halt = 2u, - context = 3u, + context = 0u, + D = 1u, + C = 2u, + halt = 3u, }; typedef uint64_t size_t; diff --git a/src/dmd/globals.d b/src/dmd/globals.d index 2a355581af65..d4125d2b76ea 100644 --- a/src/dmd/globals.d +++ b/src/dmd/globals.d @@ -44,10 +44,10 @@ enum CHECKENABLE : ubyte /// What should happend when an assertion fails enum CHECKACTION : ubyte { + context, /// call D assert with the error context on failure D, /// call D assert on failure C, /// call C assert on failure halt, /// cause program halt on failure - context, /// call D assert with the error context on failure } /// Position Indepent Code setting @@ -193,7 +193,8 @@ extern (C++) struct Param CHECKENABLE useSwitchError = CHECKENABLE._default; // check for switches without a default CHECKENABLE boundscheck = CHECKENABLE._default; // state of -boundscheck switch - CHECKACTION checkAction = CHECKACTION.D; // action to take when bounds, asserts or switch defaults are violated + /// Action to take when bounds, asserts or switch defaults are violated + CHECKACTION checkAction = CHECKACTION.context; uint errorLimit = 20; diff --git a/src/dmd/globals.h b/src/dmd/globals.h index 6e794748beee..6da65c7acba3 100644 --- a/src/dmd/globals.h +++ b/src/dmd/globals.h @@ -47,10 +47,10 @@ enum typedef unsigned char CHECKACTION; enum { + CHECKACTION_context, // call D assert with the error context on failure CHECKACTION_D, // call D assert on failure CHECKACTION_C, // call C assert on failure - CHECKACTION_halt, // cause program halt on failure - CHECKACTION_context // call D assert with the error context on failure + CHECKACTION_halt // cause program halt on failure }; enum JsonFieldFlags diff --git a/test/runnable/complex.d b/test/runnable/complex.d index 5495e0ffceca..290c5173207c 100644 --- a/test/runnable/complex.d +++ b/test/runnable/complex.d @@ -1,5 +1,5 @@ /* -REQUIRED_ARGS: -d +REQUIRED_ARGS: -d -checkaction=D TEST_OUTPUT: --- --- diff --git a/test/runnable/iasm.d b/test/runnable/iasm.d index af6366d22bdc..810802f08f3f 100644 --- a/test/runnable/iasm.d +++ b/test/runnable/iasm.d @@ -1,4 +1,5 @@ // PERMUTE_ARGS: +// REQUIRED_ARGS: -checkaction=D // Copyright (c) 1999-2016 by The D Language Foundation // All Rights Reserved diff --git a/test/runnable/iasm64.d b/test/runnable/iasm64.d index 68eab23d8a43..12f8730f238a 100644 --- a/test/runnable/iasm64.d +++ b/test/runnable/iasm64.d @@ -1,4 +1,5 @@ // PERMUTE_ARGS: +// REQUIRED_ARGS: -checkaction=D // Copyright (c) 1999-2016 by The D Language Foundation // All Rights Reserved @@ -7021,4 +7022,3 @@ else { int main() { return 0; } } -