[cfe-commits] r165678 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaCXX/attr-format.cpp test/SemaCXX/vararg-non-pod.cpp

Eli Friedman eli.friedman at gmail.com
Wed Oct 10 17:30:59 PDT 2012


Author: efriedma
Date: Wed Oct 10 19:30:58 2012
New Revision: 165678

URL: http://llvm.org/viewvc/llvm-project?rev=165678&view=rev
Log:
Make sure we perform the variadic method check correctly for calls to a member operator().  PR14057.


Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/SemaCXX/attr-format.cpp
    cfe/trunk/test/SemaCXX/vararg-non-pod.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=165678&r1=165677&r2=165678&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Oct 10 19:30:58 2012
@@ -542,11 +542,23 @@
 /// and safety properties not strictly enforced by the C type system.
 bool Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall,
                              const FunctionProtoType *Proto) {
-  bool IsMemberFunction = isa<CXXMemberCallExpr>(TheCall);
+  bool IsMemberOperatorCall = isa<CXXOperatorCallExpr>(TheCall) &&
+                              isa<CXXMethodDecl>(FDecl);
+  bool IsMemberFunction = isa<CXXMemberCallExpr>(TheCall) ||
+                          IsMemberOperatorCall;
   VariadicCallType CallType = getVariadicCallType(FDecl, Proto,
                                                   TheCall->getCallee());
   unsigned NumProtoArgs = Proto ? Proto->getNumArgs() : 0;
-  checkCall(FDecl, TheCall->getArgs(), TheCall->getNumArgs(), NumProtoArgs,
+  Expr** Args = TheCall->getArgs();
+  unsigned NumArgs = TheCall->getNumArgs();
+  if (isa<CXXOperatorCallExpr>(TheCall) && isa<CXXMethodDecl>(FDecl)) {
+    // If this is a call to a member operator, hide the first argument
+    // from checkCall.
+    // FIXME: Our choice of AST representation here is less than ideal.
+    ++Args;
+    --NumArgs;
+  }
+  checkCall(FDecl, Args, NumArgs, NumProtoArgs,
             IsMemberFunction, TheCall->getRParenLoc(),
             TheCall->getCallee()->getSourceRange(), CallType);
 

Modified: cfe/trunk/test/SemaCXX/attr-format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-format.cpp?rev=165678&r1=165677&r2=165678&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-format.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-format.cpp Wed Oct 10 19:30:58 2012
@@ -14,6 +14,8 @@
       expected-error{{out of bounds}}
   const char* h3(const char*) __attribute__((format_arg(1))); // \
       expected-error{{invalid for the implicit this argument}}
+
+  void operator() (const char*, ...) __attribute__((format(printf, 2, 3)));
 };
 
 // PR5521
@@ -33,3 +35,9 @@
     s.f(str, "%s", str);
   }
 }
+
+// Make sure we interpret member operator calls as having an implicit
+// this argument.
+void test_operator_call(S s, const char* str) {
+  s("%s", str);
+}

Modified: cfe/trunk/test/SemaCXX/vararg-non-pod.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/vararg-non-pod.cpp?rev=165678&r1=165677&r2=165678&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/vararg-non-pod.cpp (original)
+++ cfe/trunk/test/SemaCXX/vararg-non-pod.cpp Wed Oct 10 19:30:58 2012
@@ -123,3 +123,21 @@
   // Make sure the error works in potentially-evaluated sizeof
   return (int)sizeof(*(Helper(Foo()), (int (*)[n])0)); // expected-warning{{cannot pass object of non-POD type}}
 }
+
+// PR14057
+namespace t10 {
+  struct F {
+    F();
+  };
+
+  struct S {
+    void operator()(F, ...);
+  };
+
+  void foo() {
+    S s;
+    F f;
+    s.operator()(f);
+    s(f);
+  }
+}





More information about the cfe-commits mailing list