forked from OSchip/llvm-project
PR12012: Fix a regression in r150419 where we would try (and fail) to
zero-initialize class types with virtual bases when constant-evaluating an initializer. llvm-svn: 150770
This commit is contained in:
parent
5bade3dc6e
commit
5d108606cc
|
@ -3387,6 +3387,11 @@ bool RecordExprEvaluator::ZeroInitialization(const Expr *E) {
|
|||
return EvaluateInPlace(Result.getUnionValue(), Info, Subobject, &VIE);
|
||||
}
|
||||
|
||||
if (isa<CXXRecordDecl>(RD) && cast<CXXRecordDecl>(RD)->getNumVBases()) {
|
||||
Info.Diag(E->getExprLoc(), diag::note_constexpr_virtual_base) << RD;
|
||||
return false;
|
||||
}
|
||||
|
||||
return HandleClassZeroInitialization(Info, E, RD, This, Result);
|
||||
}
|
||||
|
||||
|
|
|
@ -279,3 +279,17 @@ namespace CrossFuncLabelDiff {
|
|||
// CHECK: sub nsw i64 ptrtoint (i8* blockaddress(@_ZN18CrossFuncLabelDiff4testEv, {{.*}}) to i64),
|
||||
// CHECK: store i64 {{.*}}, i64* @_ZZN18CrossFuncLabelDiff4testEvE1b, align 8
|
||||
}
|
||||
|
||||
// PR12012
|
||||
namespace VirtualBase {
|
||||
struct B {};
|
||||
struct D : virtual B {};
|
||||
D d;
|
||||
// CHECK: call {{.*}}@_ZN11VirtualBase1DC1Ev
|
||||
|
||||
template<typename T> struct X : T {
|
||||
constexpr X() : T() {}
|
||||
};
|
||||
X<D> x;
|
||||
// CHECK: call {{.*}}@_ZN11VirtualBase1XINS_1DEEC1Ev
|
||||
}
|
||||
|
|
|
@ -29,3 +29,9 @@ constexpr D d1; // expected-error {{requires a user-provided default constructor
|
|||
constexpr D d2 = D(); // ok with DR1452
|
||||
static_assert(D().c == 0, "");
|
||||
static_assert(D().d == 0, "");
|
||||
|
||||
struct V : virtual C {};
|
||||
template<typename T> struct Z : T {
|
||||
constexpr Z() : V() {}
|
||||
};
|
||||
constexpr int n = Z<V>().c; // expected-error {{constant expression}} expected-note {{virtual base class}}
|
||||
|
|
Loading…
Reference in New Issue