[cfe-commits] r77000 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclCXX.cpp test/SemaCXX/constructor-initializer.cpp
Fariborz Jahanian
fjahanian at apple.com
Fri Jul 24 13:28:49 PDT 2009
Author: fjahanian
Date: Fri Jul 24 15:28:49 2009
New Revision: 77000
URL: http://llvm.org/viewvc/llvm-project?rev=77000&view=rev
Log:
More Sema check for constructor's member initializer along
with type conversion to fix ir-gen crash.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/constructor-initializer.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=77000&r1=76999&r2=77000&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jul 24 15:28:49 2009
@@ -1664,6 +1664,8 @@
def err_mem_init_not_member_or_class : Error<
"member initializer %0 does not name a non-static data member or base "
"class">;
+def err_mem_initializer_mismatch : Error<
+ "Too many arguments for member initializer %0">;
def warn_field_initialized : Warning<
"member '%0' will be initialized after">,
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=77000&r1=76999&r2=77000&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Jul 24 15:28:49 2009
@@ -725,6 +725,15 @@
C = PerformInitializationByConstructor(
FieldType, (Expr **)Args, NumArgs, IdLoc,
SourceRange(IdLoc, RParenLoc), Member->getDeclName(), IK_Direct);
+ else if (NumArgs != 1)
+ return Diag(IdLoc, diag::err_mem_initializer_mismatch)
+ << MemberOrBase << SourceRange(IdLoc, RParenLoc);
+ else {
+ Expr * NewExp = (Expr*)Args[0];
+ if (PerformCopyInitialization(NewExp, FieldType, "passing"))
+ return true;
+ Args[0] = NewExp;
+ }
// FIXME: Perform direct initialization of the member.
return new (Context) CXXBaseOrMemberInitializer(Member, (Expr **)Args,
NumArgs, C, IdLoc);
Modified: cfe/trunk/test/SemaCXX/constructor-initializer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constructor-initializer.cpp?rev=77000&r1=76999&r2=77000&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constructor-initializer.cpp (original)
+++ cfe/trunk/test/SemaCXX/constructor-initializer.cpp Fri Jul 24 15:28:49 2009
@@ -98,8 +98,7 @@
};
// FIXME. This is bad message!
-struct M { // expected-note {{candidate function}} \
- // expected-note {{candidate function}}
+struct M {
M(int i, int j); // expected-note {{candidate function}} \
// // expected-note {{candidate function}}
};
@@ -115,4 +114,11 @@
M m; // expected-error {{default constructor for 'struct M' is missing in initialization of mamber}}
};
+struct Q {
+ Q() : f1(1,2), // expected-error {{Too many arguments for member initializer 'f1'}}
+ pf(0.0) { } // expected-error {{incompatible type passing 'double', expected 'float *'}}
+ float f1;
+
+ float *pf;
+};
More information about the cfe-commits
mailing list