]> granicus.if.org Git - clang/commitdiff
Don't crash on calling static member overloaded operator, PR14120
authorNico Weber <nicolasweber@gmx.de>
Fri, 9 Nov 2012 06:06:14 +0000 (06:06 +0000)
committerNico Weber <nicolasweber@gmx.de>
Fri, 9 Nov 2012 06:06:14 +0000 (06:06 +0000)
Patch from Brian Brooks!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167604 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaOverload.cpp
test/SemaCXX/overloaded-operator-decl.cpp

index bf2b89741ab9308844e376f9f2ae91b3702f5fed..10e7ec422019ea22f9ef1f91e254227ac3c17505 100644 (file)
@@ -10997,6 +10997,11 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj,
   // that calls this method, using Object for the implicit object
   // parameter and passing along the remaining arguments.
   CXXMethodDecl *Method = cast<CXXMethodDecl>(Best->Function);
+
+  // An error diagnostic has already been printed when parsing the declaration.
+  if (Method->isStatic())
+    return ExprError();
+
   const FunctionProtoType *Proto =
     Method->getType()->getAs<FunctionProtoType>();
 
index 4519a2d1f9adfa60c8062d32f67557b21e5d62ca..972e2deac29edaddad872ff35901ece3ddb831b7 100644 (file)
@@ -48,3 +48,13 @@ struct PR10839 {
   operator int; // expected-error{{'operator int' cannot be the name of a variable or data member}}
   int operator+; // expected-error{{'operator+' cannot be the name of a variable or data member}}
 };
+
+namespace PR14120 {
+  struct A {
+    static void operator()(int& i) { ++i; } // expected-error{{overloaded 'operator()' cannot be a static member function}}
+  };
+  void f() {
+    int i = 0;
+    A()(i);
+  }
+}