r184211 - PR14503: Don't assert if a constexpr constructor temploid instantiates to a
Richard Smith
richard-llvm at metafoo.co.uk
Tue Jun 18 10:51:52 PDT 2013
Author: rsmith
Date: Tue Jun 18 12:51:51 2013
New Revision: 184211
URL: http://llvm.org/viewvc/llvm-project?rev=184211&view=rev
Log:
PR14503: Don't assert if a constexpr constructor temploid instantiates to a
constructor that does not initialize all members, and that constructor is used
to initialize a global.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td?rev=184211&r1=184210&r2=184211&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td Tue Jun 18 12:51:51 2013
@@ -38,6 +38,8 @@ def note_constexpr_nonliteral : Note<
def note_constexpr_non_global : Note<
"%select{pointer|reference}0 to %select{|subobject of }1"
"%select{temporary|%3}2 is not a constant expression">;
+def note_constexpr_uninitialized : Note<
+ "subobject of type %0 is not initialized">;
def note_constexpr_array_index : Note<"cannot refer to element %0 of "
"%select{array of %2 elements|non-array object}1 in a constant expression">;
def note_constexpr_float_arithmetic : Note<
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=184211&r1=184210&r2=184211&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Jun 18 12:51:51 2013
@@ -1132,6 +1132,11 @@ static bool CheckLiteralType(EvalInfo &I
/// check that the expression is of literal type.
static bool CheckConstantExpression(EvalInfo &Info, SourceLocation DiagLoc,
QualType Type, const APValue &Value) {
+ if (Value.isUninit()) {
+ Info.Diag(DiagLoc, diag::note_constexpr_uninitialized) << Type;
+ return false;
+ }
+
// Core issue 1454: For a literal constant expression of array or class type,
// each subobject of its value shall have been initialized by a constant
// expression.
Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp?rev=184211&r1=184210&r2=184211&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp Tue Jun 18 12:51:51 2013
@@ -314,3 +314,23 @@ namespace CtorLookup {
constexpr C::C(const C&) = default;
constexpr C::C(C&) = default; // expected-error {{not constexpr}}
}
+
+namespace PR14503 {
+ template<typename> struct V {
+ union {
+ int n;
+ struct {
+ int x,
+ y;
+ };
+ };
+ constexpr V() : x(0) {}
+ };
+
+ // The constructor is still 'constexpr' here, but the result is not intended
+ // to be a constant expression. The standard is not clear on how this should
+ // work.
+ constexpr V<int> v; // expected-error {{constant expression}} expected-note {{subobject of type 'int' is not initialized}}
+
+ constexpr int k = V<int>().x; // FIXME: ok?
+}
More information about the cfe-commits
mailing list