[cfe-commits] r85249 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/SemaCXX/value-initialization.cpp
Fariborz Jahanian
fjahanian at apple.com
Tue Oct 27 09:51:19 PDT 2009
Author: fjahanian
Date: Tue Oct 27 11:51:19 2009
New Revision: 85249
URL: http://llvm.org/viewvc/llvm-project?rev=85249&view=rev
Log:
Generate constructor for value-initialization cases, even if the
implementation technique doesn't call the constructor at that point.
DR302. Fixes pr5296.
Added:
cfe/trunk/test/SemaCXX/value-initialization.cpp
Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=85249&r1=85248&r2=85249&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Oct 27 11:51:19 2009
@@ -288,7 +288,20 @@
<< FullRange);
assert(NumExprs == 0 && "Expected 0 expressions");
-
+
+ if (const RecordType *Record = Ty->getAs<RecordType>()) {
+ if (!Record->getDecl()->isUnion()) {
+ // As clarified in C++ DR302, generate constructor for
+ // value-initialization cases, even if the implementation technique
+ // doesn't call the constructor at that point.
+ ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(*this);
+ (void)PerformInitializationByConstructor(Ty, MultiExprArg(*this, 0, 0),
+ TypeRange.getBegin(),
+ TypeRange, DeclarationName(),
+ IK_Default, ConstructorArgs);
+ }
+ }
+
// C++ [expr.type.conv]p2:
// The expression T(), where T is a simple-type-specifier for a non-array
// complete object type or the (possibly cv-qualified) void type, creates an
@@ -489,7 +502,21 @@
return ExprError(Diag(StartLoc, diag::err_new_uninitialized_const)
<< TypeRange);
} else if (NumConsArgs == 0) {
- // Object is value-initialized. Do nothing.
+ // Object is value-initialized.
+ if (const RecordType *Record = AllocType->getAs<RecordType>()) {
+ if (!Record->getDecl()->isUnion()) {
+ // As clarified in C++ DR302, generate constructor for
+ // value-initialization cases, even if the implementation technique
+ // doesn't call the constructor at that point.
+ ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(*this);
+ (void)PerformInitializationByConstructor(AllocType,
+ MultiExprArg(*this, 0, 0),
+ TypeRange.getBegin(),
+ TypeRange, DeclarationName(),
+ IK_Default,
+ ConstructorArgs);
+ }
+ }
} else if (NumConsArgs == 1) {
// Object is direct-initialized.
// FIXME: What DeclarationName do we pass in here?
Added: cfe/trunk/test/SemaCXX/value-initialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/value-initialization.cpp?rev=85249&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/value-initialization.cpp (added)
+++ cfe/trunk/test/SemaCXX/value-initialization.cpp Tue Oct 27 11:51:19 2009
@@ -0,0 +1,23 @@
+// RUN: clang-cc -fsyntax-only -verify %s -std=c++0x
+
+struct A {
+ ~A();
+ const int i; // expected-note {{declared at}}
+};
+
+struct B {
+ // B is a non-POD with no user-written constructor.
+ // It has a nontrivial generated constructor.
+ const int i[12]; // expected-note {{declared at}}
+ A a;
+};
+
+int main () {
+ // Value-initializing a "B" doesn't call the default constructor for
+ // "B"; it value-initializes the members of B. Therefore it shouldn't
+ // cause an error on generation of the default constructor for the
+ // following:
+ new B(); // expected-error {{cannot define the implicit default constructor for 'struct B', because const member 'i'}}
+ (void)B();
+ (void)A(); // expected-error {{cannot define the implicit default constructor for 'struct A', because const member 'i'}}
+}
More information about the cfe-commits
mailing list