From e2a90b8bb054fc8de6c115a31bfadf7868bcf0c3 Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Sat, 22 Jun 2013 02:30:38 +0000 Subject: [PATCH] Extend -Wnon-pod-varargs to check calls made from member pointers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184629 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 3 ++- lib/Sema/SemaOverload.cpp | 3 +++ test/SemaCXX/vararg-non-pod.cpp | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index a960a3d808..27e8962f71 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -3798,7 +3798,8 @@ Sema::getVariadicCallType(FunctionDecl *FDecl, const FunctionProtoType *Proto, if (CXXMethodDecl *Method = dyn_cast_or_null(FDecl)) if (Method->isInstance()) return VariadicMethod; - } + } else if (Fn && Fn->getType() == Context.BoundMemberTy) + return VariadicMethod; return VariadicFunction; } return VariadicDoesNotApply; diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index b9daba95f6..29644b40b7 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -10895,6 +10895,9 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE, if (ConvertArgumentsForCall(call, op, 0, proto, Args, RParenLoc)) return ExprError(); + if (CheckOtherCall(call, proto)) + return ExprError(); + return MaybeBindToTemporary(call); } diff --git a/test/SemaCXX/vararg-non-pod.cpp b/test/SemaCXX/vararg-non-pod.cpp index 056d23fe33..56dafc41f1 100644 --- a/test/SemaCXX/vararg-non-pod.cpp +++ b/test/SemaCXX/vararg-non-pod.cpp @@ -31,7 +31,7 @@ void t2() c.g(10, version); void (C::*ptr)(int, ...) = &C::g; - (c.*ptr)(10, c); // TODO: This should also warn. + (c.*ptr)(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}} (c.*ptr)(10, version); C::h(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}} @@ -173,7 +173,7 @@ namespace t11 { (get_f_ptr())(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}} (get_f_ptr())(10, version); - (c.*get_m_ptr())(10, c); // TODO: This should also warn. + (c.*get_m_ptr())(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}} (c.*get_m_ptr())(10, version); (get_b_ptr())(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic block; call will abort at runtime}} @@ -182,7 +182,7 @@ namespace t11 { (arr_f_ptr[3])(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}} (arr_f_ptr[3])(10, version); - (c.*arr_m_ptr[3])(10, c); // TODO: This should also warn. + (c.*arr_m_ptr[3])(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}} (c.*arr_m_ptr[3])(10, version); (arr_b_ptr[3])(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic block; call will abort at runtime}} -- 2.40.0