xref: /netbsd-src/external/gpl3/gcc/dist/libphobos/testsuite/libphobos.exceptions/future_message.d (revision b1e838363e3c6fc78a55519254d99869742dd33c)
1 // { dg-options "-Wno-deprecated" }
2 import core.stdc.stdio;
3 
4 // Make sure basic stuff works with future Throwable.message
5 class NoMessage : Throwable
6 {
7     @nogc @safe pure nothrow this(string msg, Throwable next = null)
8     {
9         super(msg, next);
10     }
11 }
12 
13 class WithMessage : Throwable
14 {
15     @nogc @safe pure nothrow this(string msg, Throwable next = null)
16     {
17         super(msg, next);
18     }
19 
message()20     override const(char)[] message() const
21     {
22         return "I have a custom message.";
23     }
24 }
25 
26 class WithMessageNoOverride : Throwable
27 {
28     @nogc @safe pure nothrow this(string msg, Throwable next = null)
29     {
30         super(msg, next);
31     }
32 
message()33     const(char)[] message() const
34     {
35         return "I have a custom message and no override.";
36     }
37 }
38 
39 class WithMessageNoOverrideAndDifferentSignature : Throwable
40 {
41     @nogc @safe pure nothrow this(string msg, Throwable next = null)
42     {
43         super(msg, next);
44     }
45 
immutable(char)46     immutable(char)[] message()
47     {
48         return "I have a custom message and I'm nothing like Throwable.message.";
49     }
50 }
51 
test(Throwable t)52 void test(Throwable t)
53 {
54     try
55     {
56         throw t;
57     }
58     catch (Throwable e)
59     {
60         fprintf(stderr, "%.*s ", cast(int)e.message.length, e.message.ptr);
61     }
62 }
63 
main()64 void main()
65 {
66      test(new NoMessage("exception"));
67      test(new WithMessage("exception"));
68      test(new WithMessageNoOverride("exception"));
69      test(new WithMessageNoOverrideAndDifferentSignature("exception"));
70      fprintf(stderr, "\n");
71 }
72