[cfe-commits] r88858 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/CXX/special/class.free/p1.cpp

Anders Carlsson andersca at mac.com
Sun Nov 15 10:59:32 PST 2009


Author: andersca
Date: Sun Nov 15 12:59:32 2009
New Revision: 88858

URL: http://llvm.org/viewvc/llvm-project?rev=88858&view=rev
Log:
allocation functions are always static.

Added:
    cfe/trunk/test/CXX/special/class.free/p1.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=88858&r1=88857&r2=88858&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Nov 15 12:59:32 2009
@@ -2612,10 +2612,19 @@
       return 0;
     }
 
+    bool isStatic = SC == FunctionDecl::Static;
+    
+    // [class.free]p1:
+    // Any allocation function for a class T is a static member
+    // (even if not explicitly declared static).
+    if (Name.getCXXOverloadedOperator() == OO_New ||
+        Name.getCXXOverloadedOperator() == OO_Array_New)
+      isStatic = true;
+    
     // This is a C++ method declaration.
     NewFD = CXXMethodDecl::Create(Context, cast<CXXRecordDecl>(DC),
                                   D.getIdentifierLoc(), Name, R, DInfo,
-                                  (SC == FunctionDecl::Static), isInline);
+                                  isStatic, isInline);
 
     isVirtualOkay = (SC != FunctionDecl::Static);
   } else {

Added: cfe/trunk/test/CXX/special/class.free/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/special/class.free/p1.cpp?rev=88858&view=auto

==============================================================================
--- cfe/trunk/test/CXX/special/class.free/p1.cpp (added)
+++ cfe/trunk/test/CXX/special/class.free/p1.cpp Sun Nov 15 12:59:32 2009
@@ -0,0 +1,11 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+#include <stddef.h>
+
+struct A {
+  void *operator new(size_t) {
+    return this; // expected-error {{invalid use of 'this' outside of a nonstatic member function}}
+  }
+  void *operator new[](size_t) {
+    return this; // expected-error {{invalid use of 'this' outside of a nonstatic member function}}
+  }
+};





More information about the cfe-commits mailing list