dmd/compiler/test/fail_compilation/ice10651.d
Nick Treleaven 7d6ac55712
Fix Issue 12118 - Modify immutable data using throw (#14706)
* Fix Issue 12118 - Modify immutable data using throw

* Change immutable test to const

* Deprecate throwing any qualified type

* Allow throw shared as std.concurrency does that

* Use static this instead of static const for test

* Only allow single shared qualifier or none

* Add changelog

* Disallow throwing shared objects too

* Update changelog/dmd.throw-qualifier.dd

Co-authored-by: Razvan Nitu <razvan.nitu1305@gmail.com>

---------

Co-authored-by: Razvan Nitu <razvan.nitu1305@gmail.com>
2023-03-13 17:42:18 +02:00

31 lines
675 B
D

/*
TEST_OUTPUT:
---
fail_compilation/ice10651.d(13): Error: can only throw class objects derived from `Throwable`, not type `int*`
fail_compilation/ice10651.d(19): Deprecation: cannot throw object of qualified type `immutable(Exception)`
fail_compilation/ice10651.d(20): Deprecation: cannot throw object of qualified type `const(Dummy)`
---
*/
void main()
{
alias T = int;
throw new T(); // ICE
}
void f()
{
immutable c = new Exception("");
if (c) throw c;
throw new const Dummy([]);
}
class Dummy: Exception
{
int[] data;
@safe pure nothrow this(immutable int[] data) immutable
{
super("Dummy");
this.data = data;
}
}