if (!S || !N)
return false;
- // Peel off OpaqueValueExpr.
+ if (const ExprWithCleanups *EWC = dyn_cast<ExprWithCleanups>(S))
+ S = EWC->getSubExpr();
if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(S))
S = OVE->getSourceExpr();
extern bool coin();
+class SomeClass {
+public:
+ void doSomething();
+};
+
namespace References {
class Map {
int *&getNewBox();
*box = 1; // expected-warning {{Dereference of null pointer}}
}
- class SomeClass {
- public:
- void doSomething();
- };
-
SomeClass *&getSomeClass() {
if (coin()) {
extern SomeClass *&opaqueClass();
}
+namespace Cleanups {
+ class NonTrivial {
+ public:
+ ~NonTrivial();
+
+ SomeClass *getNull() {
+ return 0;
+ }
+ };
+
+ void testImmediate() {
+ NonTrivial().getNull()->doSomething();
+#ifndef SUPPRESSED
+ // expected-warning@-2 {{Called C++ object pointer is null}}
+#endif
+ }
+
+ void testAssignment() {
+ SomeClass *ptr = NonTrivial().getNull();
+ ptr->doSomething();
+#ifndef SUPPRESSED
+ // expected-warning@-2 {{Called C++ object pointer is null}}
+#endif
+ }
+
+ void testArgumentHelper(SomeClass *arg) {
+ arg->doSomething();
+#ifndef SUPPRESSED
+ // expected-warning@-2 {{Called C++ object pointer is null}}
+#endif
+ }
+
+ void testArgument() {
+ testArgumentHelper(NonTrivial().getNull());
+ }
+}