]> granicus.if.org Git - clang/commitdiff
Deallocation functions must also be static.
authorAnders Carlsson <andersca@mac.com>
Sun, 15 Nov 2009 19:08:46 +0000 (19:08 +0000)
committerAnders Carlsson <andersca@mac.com>
Sun, 15 Nov 2009 19:08:46 +0000 (19:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88859 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/CXX/special/class.free/p6.cpp [new file with mode: 0644]

index 82e9acd91a93d2bb1effc33f96b5b8fa1d64df2c..d3257c17a40501fd39f3b5f4656d46be06a43698 100644 (file)
@@ -2620,13 +2620,19 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
     if (Name.getCXXOverloadedOperator() == OO_New ||
         Name.getCXXOverloadedOperator() == OO_Array_New)
       isStatic = true;
+
+    // [class.free]p6 Any deallocation function for a class X is a static member
+    // (even if not explicitly declared static).
+    if (Name.getCXXOverloadedOperator() == OO_Delete ||
+        Name.getCXXOverloadedOperator() == OO_Array_Delete)
+      isStatic = true;
     
     // This is a C++ method declaration.
     NewFD = CXXMethodDecl::Create(Context, cast<CXXRecordDecl>(DC),
                                   D.getIdentifierLoc(), Name, R, DInfo,
                                   isStatic, isInline);
 
-    isVirtualOkay = (SC != FunctionDecl::Static);
+    isVirtualOkay = !isStatic;
   } else {
     // Determine whether the function was written with a
     // prototype. This true when:
diff --git a/test/CXX/special/class.free/p6.cpp b/test/CXX/special/class.free/p6.cpp
new file mode 100644 (file)
index 0000000..8334817
--- /dev/null
@@ -0,0 +1,11 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+#include <stddef.h>
+
+struct A {
+  void operator delete(size_t) {
+    (void)this; // expected-error {{invalid use of 'this' outside of a nonstatic member function}}
+  }
+  void operator delete[](void*) {
+    (void)this; // expected-error {{invalid use of 'this' outside of a nonstatic member function}}
+  }
+};