[cfe-commits] r80802 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/CodeGenCXX/trivial-constructor-init.cpp
Fariborz Jahanian
fjahanian at apple.com
Wed Sep 2 10:10:17 PDT 2009
Author: fjahanian
Date: Wed Sep 2 12:10:17 2009
New Revision: 80802
URL: http://llvm.org/viewvc/llvm-project?rev=80802&view=rev
Log:
Allow null initialization of scalara data members
in constructors's initializer list. pr4854
Added:
cfe/trunk/test/CodeGenCXX/trivial-constructor-init.cpp
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=80802&r1=80801&r2=80802&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Sep 2 12:10:17 2009
@@ -786,11 +786,17 @@
C = PerformInitializationByConstructor(
FieldType, (Expr **)Args, NumArgs, IdLoc,
SourceRange(IdLoc, RParenLoc), Member->getDeclName(), IK_Direct);
- } else if (NumArgs != 1) {
+ } else if (NumArgs != 1 && NumArgs != 0) {
return Diag(IdLoc, diag::err_mem_initializer_mismatch)
<< Member->getDeclName() << SourceRange(IdLoc, RParenLoc);
} else if (!HasDependentArg) {
- Expr *NewExp = (Expr*)Args[0];
+ Expr *NewExp;
+ if (NumArgs == 0) {
+ NewExp = new (Context) CXXZeroInitValueExpr(FieldType, IdLoc, RParenLoc);
+ NumArgs = 1;
+ }
+ else
+ NewExp = (Expr*)Args[0];
if (PerformCopyInitialization(NewExp, FieldType, "passing"))
return true;
Args[0] = NewExp;
Added: cfe/trunk/test/CodeGenCXX/trivial-constructor-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/trivial-constructor-init.cpp?rev=80802&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/trivial-constructor-init.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/trivial-constructor-init.cpp Wed Sep 2 12:10:17 2009
@@ -0,0 +1,21 @@
+// RUN: clang-cc -S %s -o %t-64.s &&
+// RUN: clang-cc -S %s -o %t-32.s &&
+// RUN: true
+
+extern "C" int printf(...);
+
+struct S {
+ S() { printf("S::S\n"); }
+};
+
+struct A {
+ double x;
+ A() : x(), y(), s() { printf("x = %f y = %x \n", x, y); }
+ int *y;
+ S s;
+};
+
+A a;
+
+int main() {
+}
More information about the cfe-commits
mailing list