[cfe-commits] r167604 - in /cfe/trunk: lib/Sema/SemaOverload.cpp test/SemaCXX/overloaded-operator-decl.cpp

Nico Weber nicolasweber at gmx.de
Thu Nov 8 22:06:14 PST 2012


Author: nico
Date: Fri Nov  9 00:06:14 2012
New Revision: 167604

URL: http://llvm.org/viewvc/llvm-project?rev=167604&view=rev
Log:
Don't crash on calling static member overloaded operator, PR14120

Patch from Brian Brooks!


Modified:
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/SemaCXX/overloaded-operator-decl.cpp

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=167604&r1=167603&r2=167604&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Nov  9 00:06:14 2012
@@ -10997,6 +10997,11 @@
   // 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>();
 

Modified: cfe/trunk/test/SemaCXX/overloaded-operator-decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overloaded-operator-decl.cpp?rev=167604&r1=167603&r2=167604&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/overloaded-operator-decl.cpp (original)
+++ cfe/trunk/test/SemaCXX/overloaded-operator-decl.cpp Fri Nov  9 00:06:14 2012
@@ -48,3 +48,13 @@
   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);
+  }
+}





More information about the cfe-commits mailing list