[cfe-commits] r88859 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/CXX/special/class.free/p6.cpp
Anders Carlsson
andersca at mac.com
Sun Nov 15 11:08:47 PST 2009
Author: andersca
Date: Sun Nov 15 13:08:46 2009
New Revision: 88859
URL: http://llvm.org/viewvc/llvm-project?rev=88859&view=rev
Log:
Deallocation functions must also be static.
Added:
cfe/trunk/test/CXX/special/class.free/p6.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=88859&r1=88858&r2=88859&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Nov 15 13:08:46 2009
@@ -2620,13 +2620,19 @@
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:
Added: cfe/trunk/test/CXX/special/class.free/p6.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/special/class.free/p6.cpp?rev=88859&view=auto
==============================================================================
--- cfe/trunk/test/CXX/special/class.free/p6.cpp (added)
+++ cfe/trunk/test/CXX/special/class.free/p6.cpp Sun Nov 15 13:08:46 2009
@@ -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}}
+ }
+};
More information about the cfe-commits
mailing list