[cfe-commits] r150770 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/CodeGenCXX/const-init-cxx11.cpp test/SemaCXX/constexpr-value-init.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Thu Feb 16 16:44:16 PST 2012
Author: rsmith
Date: Thu Feb 16 18:44:16 2012
New Revision: 150770
URL: http://llvm.org/viewvc/llvm-project?rev=150770&view=rev
Log:
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.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp
cfe/trunk/test/SemaCXX/constexpr-value-init.cpp
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=150770&r1=150769&r2=150770&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Feb 16 18:44:16 2012
@@ -3387,6 +3387,11 @@
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);
}
Modified: cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp?rev=150770&r1=150769&r2=150770&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp Thu Feb 16 18:44:16 2012
@@ -279,3 +279,17 @@
// 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
+}
Modified: cfe/trunk/test/SemaCXX/constexpr-value-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constexpr-value-init.cpp?rev=150770&r1=150769&r2=150770&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constexpr-value-init.cpp (original)
+++ cfe/trunk/test/SemaCXX/constexpr-value-init.cpp Thu Feb 16 18:44:16 2012
@@ -29,3 +29,9 @@
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}}
More information about the cfe-commits
mailing list