From: Fariborz Jahanian Date: Fri, 24 Jul 2009 20:28:49 +0000 (+0000) Subject: More Sema check for constructor's member initializer along X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7252f5110de3163a465aa50a2114c1fef9e848e8;p=clang More Sema check for constructor's member initializer along with type conversion to fix ir-gen crash. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77000 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 881e9d90a1..9031a6ec9c 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1664,6 +1664,8 @@ def error_multiple_base_initialization : Error < 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">, diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index d5c8c3d3fc..7b0c9c6ca4 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -725,6 +725,15 @@ Sema::ActOnMemInitializer(DeclPtrTy ConstructorD, 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); diff --git a/test/SemaCXX/constructor-initializer.cpp b/test/SemaCXX/constructor-initializer.cpp index 71d38a1438..3909cd984d 100644 --- a/test/SemaCXX/constructor-initializer.cpp +++ b/test/SemaCXX/constructor-initializer.cpp @@ -98,8 +98,7 @@ struct Current : Derived { }; // 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 @@ struct P : M { // expected-error {{default constructor for 'struct M' is missin 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; +};