gdc ice
Iain Buclaw
ibuclaw at gdcproject.org
Wed Aug 9 12:44:16 UTC 2023
On Wednesday, 9 August 2023 at 11:48:41 UTC, Adam D Ruppe wrote:
> $ cat gdcbug.d
> class ArsdExceptionBase : object.Exception {
> package this(string operation, string file = __FILE__,
> size_t line = __LINE__, Throwable next = null) {
> super(operation, file, line, next);
> }
> }
>
> template ArsdException(alias Type, DataTuple...) {
> static if(DataTuple.length)
> alias Parent = ArsdException!(Type, DataTuple[0
> .. $-1]);
> else
> alias Parent = ArsdExceptionBase;
>
> class ArsdException : Parent {
> DataTuple data;
>
> this(DataTuple data, string file = __FILE__,
> size_t line = __LINE__) {
> this.data = data;
> static if(is(Parent ==
> ArsdExceptionBase))
> super(null, file, line);
> else
> super(data[0 .. $-1], file,
> line);
> }
>
> static opCall(R...)(R r, string file =
> __FILE__, size_t line = __LINE__) {
> return new ArsdException!(Type,
> DataTuple, R)(r, file, line);
> }
> }
> }
>
> /// This example shows how you can throw and catch the ad-hoc
> exception types.
> void main() {
> // 0 or 1 args works
> try {
> throw ArsdException!"Test"(1);
> } catch(ArsdException!"Test" e) { // catch it without
> them
> }
>
> // 2 or more args causes ice
> try {
> throw ArsdException!"Test"(4, "four");
> } catch(ArsdException!("Test", int, string) e) { //
> catch it and use info by specifying types
> assert(e.data[0] == 4); // and extract
> arguments like this
> assert(e.data[1] == "four");
> }
> }
Can you raise a bug report against gcc.gnu.org/bugzilla?
Only affects gdc-12.x - there's still time to fix before 12.4 is
released.
```
==> gcc-9/gdc
arsd.d:19:38: error: constructor arsd.ArsdExceptionBase.this is
not accessible from module arsd
19 | super(null, file, line);
| ^
```
```
==> gcc-10//gdc
arsd.d:19:38: error: constructor arsd.ArsdExceptionBase.this is
not accessible from module arsd
19 | super(null, file, line);
| ^
```
```
==> gcc-11//gdc
arsd.d:34:43: error: template
arsd.ArsdException!"Test".ArsdException.opCall cannot deduce
function from argument types !()(int), candidates are:
34 | throw ArsdException!"Test"(1);
| ^
```
```
==> gcc-12/gdc
arsd.d: In function ‘D main’:
arsd.d:40:23: internal compiler error: in layout_aggregate_type,
at d/types.cc:574
40 | throw ArsdException!"Test"(4, "four");
| ^
0x7d507f layout_aggregate_type
../../gcc/d/types.cc:574
...
```
```
==> gcc-13/gdc
OK!
```
```
==> gcc-mainline/gdc
OK!
```
More information about the D.gnu
mailing list