mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 05:00:16 +03:00
Fix Issue 21415 - catch immutable exceptions breaks immutable (#14707)
* Fix Issue 21415 - catch immutable exceptions breaks immutable * Disallow catching inout and shared too * Workaround catch(shared) in eh2.d
This commit is contained in:
parent
6afed16ccc
commit
0659c9b577
3 changed files with 23 additions and 2 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue