You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -26,11 +27,11 @@ class PolymorphicMultiDerived : public Base, public PolymorphicBase {
26
27
voidpointers() {
27
28
28
29
auto P0 = static_cast<Derived*>(newBase());
29
-
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
30
+
// CHECK-MESSAGES-STRICT: :[[@LINE-1]]:13: warning: do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
30
31
31
32
const Base* B0;
32
33
auto PC0 = static_cast<const Derived*>(B0);
33
-
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
34
+
// CHECK-MESSAGES-STRICT: :[[@LINE-1]]:14: warning: do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
34
35
35
36
auto P1 = static_cast<Base*>(newDerived()); // OK, upcast to a public base
36
37
auto P2 = static_cast<Base*>(newMultiDerived()); // OK, upcast to a public base
@@ -40,13 +41,13 @@ void pointers() {
40
41
voidpointers_polymorphic() {
41
42
42
43
auto PP0 = static_cast<PolymorphicDerived*>(newPolymorphicBase());
43
-
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-static-cast-downcast]
44
-
// CHECK-FIXES: auto PP0 = dynamic_cast<PolymorphicDerived*>(new PolymorphicBase());
44
+
// CHECK-MESSAGES-NSTRICT: :[[@LINE-1]]:14: warning: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-static-cast-downcast]
45
+
// CHECK-FIXES-NSTRICT: auto PP0 = dynamic_cast<PolymorphicDerived*>(new PolymorphicBase());
45
46
46
47
const PolymorphicBase* B0;
47
48
auto PPC0 = static_cast<const PolymorphicDerived*>(B0);
48
-
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-static-cast-downcast]
49
-
// CHECK-FIXES: auto PPC0 = dynamic_cast<const PolymorphicDerived*>(B0);
49
+
// CHECK-MESSAGES-NSTRICT: :[[@LINE-1]]:15: warning: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-static-cast-downcast]
50
+
// CHECK-FIXES-NSTRICT: auto PPC0 = dynamic_cast<const PolymorphicDerived*>(B0);
50
51
51
52
52
53
auto B1 = static_cast<PolymorphicBase*>(newPolymorphicDerived()); // OK, upcast to a public base
@@ -57,27 +58,27 @@ void pointers_polymorphic() {
57
58
voidarrays() {
58
59
Base ArrayOfBase[10];
59
60
auto A0 = static_cast<Derived*>(ArrayOfBase);
60
-
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
61
+
// CHECK-MESSAGES-STRICT: :[[@LINE-1]]:13: warning: do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
61
62
}
62
63
63
64
voidarrays_polymorphic() {
64
65
PolymorphicBase ArrayOfPolymorphicBase[10];
65
66
auto AP0 = static_cast<PolymorphicDerived*>(ArrayOfPolymorphicBase);
66
-
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead
67
-
// CHECK-FIXES: auto AP0 = dynamic_cast<PolymorphicDerived*>(ArrayOfPolymorphicBase);
67
+
// CHECK-MESSAGES-NSTRICT: :[[@LINE-1]]:14: warning: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead
68
+
// CHECK-FIXES-NSTRICT: auto AP0 = dynamic_cast<PolymorphicDerived*>(ArrayOfPolymorphicBase);
68
69
}
69
70
70
71
voidreferences() {
71
72
Base B0;
72
73
auto R0 = static_cast<Derived&>(B0);
73
-
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
74
+
// CHECK-MESSAGES-STRICT: :[[@LINE-1]]:13: warning: do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
74
75
Base& RefToBase = B0;
75
76
auto R1 = static_cast<Derived&>(RefToBase);
76
-
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
77
+
// CHECK-MESSAGES-STRICT: :[[@LINE-1]]:13: warning: do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
77
78
78
79
const Base& ConstRefToBase = B0;
79
80
auto RC1 = static_cast<const Derived&>(ConstRefToBase);
80
-
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
81
+
// CHECK-MESSAGES-STRICT: :[[@LINE-1]]:14: warning: do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
81
82
82
83
83
84
Derived RD1;
@@ -87,18 +88,18 @@ void references() {
87
88
voidreferences_polymorphic() {
88
89
PolymorphicBase B0;
89
90
auto RP0 = static_cast<PolymorphicDerived&>(B0);
90
-
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead
91
-
// CHECK-FIXES: auto RP0 = dynamic_cast<PolymorphicDerived&>(B0);
91
+
// CHECK-MESSAGES-NSTRICT: :[[@LINE-1]]:14: warning: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead
92
+
// CHECK-FIXES-NSTRICT: auto RP0 = dynamic_cast<PolymorphicDerived&>(B0);
92
93
93
94
PolymorphicBase& RefToPolymorphicBase = B0;
94
95
auto RP1 = static_cast<PolymorphicDerived&>(RefToPolymorphicBase);
95
-
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-static-cast-downcast]
96
-
// CHECK-FIXES: auto RP1 = dynamic_cast<PolymorphicDerived&>(RefToPolymorphicBase);
96
+
// CHECK-MESSAGES-NSTRICT: :[[@LINE-1]]:14: warning: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-static-cast-downcast]
97
+
// CHECK-FIXES-NSTRICT: auto RP1 = dynamic_cast<PolymorphicDerived&>(RefToPolymorphicBase);
auto RPC2 = static_cast<const PolymorphicDerived&>(ConstRefToPolymorphicBase);
100
-
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-static-cast-downcast]
101
-
// CHECK-FIXES: auto RPC2 = dynamic_cast<const PolymorphicDerived&>(ConstRefToPolymorphicBase);
101
+
// CHECK-MESSAGES-NSTRICT: :[[@LINE-1]]:15: warning: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-static-cast-downcast]
102
+
// CHECK-FIXES-NSTRICT: auto RPC2 = dynamic_cast<const PolymorphicDerived&>(ConstRefToPolymorphicBase);
102
103
103
104
PolymorphicDerived d1;
104
105
auto RP2 = static_cast<PolymorphicBase&>(d1); // OK, upcast to a public base
0 commit comments