Debian Codegraph @

gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics7.C

raw
1 // P0847R7
2 // { dg-do compile { target c++23 } }
3
4 // diagnose xobj member functions that override
5 // or are declared as virtual, override, or final
6
7 struct B {
8 virtual void f0() {} // { dg-note {virtual function declared here} }
9 virtual void f1() {} // { dg-note {virtual function declared here} }
10 virtual void f2() {} // { dg-note {virtual function declared here} }
11 virtual void f3() {} // { dg-note {virtual function declared here} }
12 virtual void f4() {} // { dg-note {virtual function declared here} }
13 virtual void f5() {} // { dg-note {virtual function declared here} }
14 virtual void f6() {} // { dg-note {virtual function declared here} }
15 virtual void f7() {} // { dg-note {virtual function declared here} }
16 virtual ~B() {}
17 };
18
19 struct S : B {
20 virtual void f0(this S&) {} // { dg-line line_f0 }
21 virtual void f1(this S&) override {} // { dg-line line_f1 }
22 virtual void f2(this S&) final {} // { dg-line line_f2 }
23 virtual void f3(this S&) override final {} // { dg-line line_f3 }
24 void f4(this S&) {} // { dg-line line_f4 }
25 void f5(this S&) override {} // { dg-line line_f5 }
26 void f6(this S&) final {} // { dg-line line_f6 }
27 void f7(this S&) override final {} // { dg-line line_f7 }
28 };
29
30 // { dg-error {an explicit object member function cannot be 'virtual'} "" { target *-*-* } line_f0 }
31 // { dg-error {an explicit object member function cannot be 'virtual'} "" { target *-*-* } line_f1 }
32 // { dg-error {an explicit object member function cannot be 'virtual'} "" { target *-*-* } line_f2 }
33 // { dg-error {an explicit object member function cannot be 'virtual'} "" { target *-*-* } line_f3 }
34
35 // { dg-error {explicit object member function overrides virtual function} "" { target *-*-* } line_f0 }
36 // { dg-error {explicit object member function overrides virtual function} "" { target *-*-* } line_f1 }
37 // { dg-error {explicit object member function overrides virtual function} "" { target *-*-* } line_f2 }
38 // { dg-error {explicit object member function overrides virtual function} "" { target *-*-* } line_f3 }
39 // { dg-error {explicit object member function overrides virtual function} "" { target *-*-* } line_f4 }
40 // { dg-error {explicit object member function overrides virtual function} "" { target *-*-* } line_f5 }
41 // { dg-error {explicit object member function overrides virtual function} "" { target *-*-* } line_f6 }
42 // { dg-error {explicit object member function overrides virtual function} "" { target *-*-* } line_f7 }
43
44 // these should be suppressed, the wording conflicts with the error
45 // the issue is not that they don't override, it's that they do override, and that isn't allowed
46 // { dg-bogus "marked 'override', but does not override" "" { target *-*-* } line_f1 }
47 // { dg-bogus "marked 'final', but is not virtual" "" { xfail *-*-* } line_f2 }
48 // { dg-bogus "marked '(override|final)'" "" { xfail *-*-* } line_f3 }
49
50 // { dg-bogus "marked 'override', but does not override" "" { target *-*-* } line_f5 }
51 // { dg-bogus "marked 'final', but is not virtual" "" { xfail *-*-* } line_f6 }
52 // { dg-bogus "marked '(override|final)'" "" { xfail *-*-* } line_f7 }
53
54 // { dg-note "explicit object parameter declared here" "" { target *-*-* } line_f0 }
55 // { dg-note "explicit object parameter declared here" "" { target *-*-* } line_f1 }
56 // { dg-note "explicit object parameter declared here" "" { target *-*-* } line_f2 }
57 // { dg-note "explicit object parameter declared here" "" { target *-*-* } line_f3 }
58 // { dg-note "explicit object parameter declared here" "" { xfail *-*-* } line_f4 }
59 // { dg-note "explicit object parameter declared here" "" { xfail *-*-* } line_f5 }
60 // { dg-note "explicit object parameter declared here" "" { xfail *-*-* } line_f6 }
61 // { dg-note "explicit object parameter declared here" "" { xfail *-*-* } line_f7 }
62
63 struct S1 {
64 virtual void f0(this S&) {} // { dg-line line_S1_f0 }
65 virtual void f1(this S&) override {} // { dg-line line_S1_f1 }
66 virtual void f2(this S&) final {} // { dg-line line_S1_f2 }
67 virtual void f3(this S&) override final {} // { dg-line line_S1_f3 }
68 void f4(this S&) {}
69 void f5(this S&) override {} // { dg-line line_S1_f5 }
70 void f6(this S&) final {} // { dg-line line_S1_f6 }
71 void f7(this S&) override final {} // { dg-line line_S1_f7 }
72 };
73
74 // { dg-error "an explicit object member function cannot be 'virtual'" "" { target *-*-* } line_S1_f0 }
75 // { dg-error "an explicit object member function cannot be 'virtual'" "" { target *-*-* } line_S1_f1 }
76 // { dg-error "an explicit object member function cannot be 'virtual'" "" { target *-*-* } line_S1_f2 }
77 // { dg-error "an explicit object member function cannot be 'virtual'" "" { target *-*-* } line_S1_f3 }
78
79 // { dg-note "explicit object parameter declared here" "" { target *-*-* } line_S1_f0 }
80 // { dg-note "explicit object parameter declared here" "" { target *-*-* } line_S1_f1 }
81 // { dg-note "explicit object parameter declared here" "" { target *-*-* } line_S1_f2 }
82 // { dg-note "explicit object parameter declared here" "" { target *-*-* } line_S1_f3 }
83
84 // I think I want these suppressed, but theres a decent argument that they should stay
85 // theres arguably no reason the error about virtual should suppress these
86 // { dg-bogus "marked 'override', but does not override" "" { xfail *-*-* } line_S1_f1 }
87 // { dg-bogus "marked 'final', but is not virtual" "" { xfail *-*-* } line_S1_f2 }
88 // { dg-bogus "marked '(override|final)'" "" { xfail *-*-* } line_S1_f3 }
89
90 // I don't want to suppress these, there is nothing that could possibly be overridden
91 // even if the xobj param was removed
92 // { dg-error "marked 'override', but does not override" "" { target *-*-* } line_S1_f5 }
93 // { dg-error "marked 'final', but is not virtual" "" { target *-*-* } line_S1_f6 }
94 // { dg-error "marked '(override|final)'" "" { target *-*-* } line_S1_f7 }
95