if (BO->getOpcode() == BO_Comma)
return isGLValueFromPointerDeref(BO->getRHS());
- if (const auto *CO = dyn_cast<ConditionalOperator>(E))
- return isGLValueFromPointerDeref(CO->getTrueExpr()) ||
- isGLValueFromPointerDeref(CO->getFalseExpr());
-
- if (const auto *BCO = dyn_cast<BinaryConditionalOperator>(E))
- if (const auto *OVE = dyn_cast<OpaqueValueExpr>(BCO->getTrueExpr()))
- return isGLValueFromPointerDeref(OVE->getSourceExpr()) ||
- isGLValueFromPointerDeref(BCO->getFalseExpr());
+ if (const auto *ACO = dyn_cast<AbstractConditionalOperator>(E))
+ return isGLValueFromPointerDeref(ACO->getTrueExpr()) ||
+ isGLValueFromPointerDeref(ACO->getFalseExpr());
// C++11 [expr.sub]p1:
// The expression E1[E2] is identical (by definition) to *((E1)+(E2))
// If the glvalue expression is obtained by applying the unary * operator to
// a pointer and the pointer is a null pointer value, the typeid expression
// throws the std::bad_typeid exception.
+ //
+ // However, this paragraph's intent is not clear. We choose a very generous
+ // interpretation which implores us to consider comma operators, conditional
+ // operators, parentheses and other such constructs.
QualType SrcRecordTy = E->getType();
if (CGF.CGM.getCXXABI().shouldTypeidBeNullChecked(
isGLValueFromPointerDeref(E), SrcRecordTy)) {
-// RUN: %clang_cc1 %s -triple %itanium_abi_triple -Wno-unused-value -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -Wno-unused-value -emit-llvm -o - -std=c++11 | FileCheck %s
namespace std {
struct type_info;
}
struct A {
virtual ~A();
+ operator bool();
};
struct B : A {};
// CHECK: icmp eq {{.*}}, null
// CHECK-NEXT: br i1
-void f10(A *x) { typeid((const A &)(A)*x); }
-// CHECK-LABEL: define void @_Z3f10P1A
+void f10(A *x, A *y) { typeid(*y ?: *x); }
+// CHECK-LABEL: define void @_Z3f10P1AS0_
+// CHECK: icmp eq {{.*}}, null
+// CHECK-NEXT: br i1
+
+void f11(A *x) { typeid((const A &)(A)*x); }
+// CHECK-LABEL: define void @_Z3f11P1A
+// CHECK-NOT: icmp eq {{.*}}, null
+
+void f12(A *x) { typeid((A &&)*(A *)nullptr); }
+// CHECK-LABEL: define void @_Z3f12P1A
// CHECK-NOT: icmp eq {{.*}}, null