diff --git a/compiler/src/dmd/statementsem.d b/compiler/src/dmd/statementsem.d index f849ce1f69..210c29c72a 100644 --- a/compiler/src/dmd/statementsem.d +++ b/compiler/src/dmd/statementsem.d @@ -4045,6 +4045,13 @@ void catchSemantic(Catch c, Scope* sc) // reference .object.Throwable c.type = getThrowable(); } + else if (!c.type.isNaked() && !c.type.isConst()) + { + // @@@DEPRECATED_2.113@@@ + // Deprecated in 2.103, change into an error & uncomment in 2.113 + deprecation(c.loc, "can only catch mutable or const qualified types, not `%s`", c.type.toChars()); + //c.errors = true; + } c.type = c.type.typeSemantic(c.loc, sc); if (c.type == Type.terror) { diff --git a/compiler/test/fail_compilation/fail2456.d b/compiler/test/fail_compilation/fail2456.d index 08e11da201..5d7d6eebd2 100644 --- a/compiler/test/fail_compilation/fail2456.d +++ b/compiler/test/fail_compilation/fail2456.d @@ -108,3 +108,17 @@ void test2456b() catch (Throwable) {} // NG } } + +/* +TEST_OUTPUT: +--- +fail_compilation/fail2456.d(121): Deprecation: can only catch mutable or const qualified types, not `immutable(Exception)` +--- +*/ +void main() { + try { + throw new Exception(""); + } catch (immutable Exception e) { + assert(0); + } +} diff --git a/compiler/test/runnable/eh2.d b/compiler/test/runnable/eh2.d index 2b469d2f80..775e83d3bf 100644 --- a/compiler/test/runnable/eh2.d +++ b/compiler/test/runnable/eh2.d @@ -72,11 +72,11 @@ int main() a.test(); Abc.x |= 0x40; } - catch (shared(Abc) b) + catch (Abc b) { Abc.x |= 0x80; printf("Caught %p, x = x%x\n", b, Abc.x); - assert(a is b); + assert(cast() a is b); assert(Abc.x == 0xB5); } printf("Success!\n");