diff options
author | Anders Carlsson <andersca@mac.com> | 2009-11-15 19:08:46 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-11-15 19:08:46 +0000 |
commit | 1f126bd18c85ea129c3897f8729cebb090917d01 (patch) | |
tree | e89fe037a022e2f869ad0221a56da95dac1800c7 | |
parent | 67bf2e7706b82d5debd5c189d9454130df7db0d8 (diff) |
Deallocation functions must also be static.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88859 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 8 | ||||
-rw-r--r-- | test/CXX/special/class.free/p6.cpp | 11 |
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 82e9acd91a..d3257c17a4 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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 index 0000000000..8334817ca2 --- /dev/null +++ b/test/CXX/special/class.free/p6.cpp @@ -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}} + } +}; |