Skip to content

Commit bc14ed7

Browse files
Anders LanglandsAaronBallman
Anders Langlands
authored andcommitted
Add clang_CXXMethod_isDeleted function
Adds a function to check if a method has been deleted by copy-pasting the existing implementation of clang_CXXMethod_isDefaulted and changing it to call CXXMethod::isDeleted() instead. Differential Revision: https://reviews.llvm.org/D133924
1 parent 9f13b93 commit bc14ed7

File tree

8 files changed

+46
-2
lines changed

8 files changed

+46
-2
lines changed

clang/bindings/python/clang/cindex.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,12 @@ def is_default_method(self):
14731473
"""
14741474
return conf.lib.clang_CXXMethod_isDefaulted(self)
14751475

1476+
def is_deleted_method(self):
1477+
"""Returns True if the cursor refers to a C++ member function or member
1478+
function template that is declared '= delete'.
1479+
"""
1480+
return conf.lib.clang_CXXMethod_isDeleted(self)
1481+
14761482
def is_mutable_field(self):
14771483
"""Returns True if the cursor refers to a C++ field that is declared
14781484
'mutable'.
@@ -3426,6 +3432,10 @@ def cursor(self):
34263432
[Cursor],
34273433
bool),
34283434

3435+
("clang_CXXMethod_isDeleted",
3436+
[Cursor],
3437+
bool),
3438+
34293439
("clang_CXXMethod_isPureVirtual",
34303440
[Cursor],
34313441
bool),

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ libclang
398398
the behavior of ``QualType::getUnqualifiedType`` for ``CXType``.
399399
- Introduced the new function ``clang_getNonReferenceType``, which mimics
400400
the behavior of ``QualType::getNonReferenceType`` for ``CXType``.
401+
- Introduced the new function ``clang_CXXMethod_isDeleted``, which queries
402+
whether the method is declared ``= delete``.
401403

402404
Static Analyzer
403405
---------------

clang/include/clang-c/Index.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4924,6 +4924,11 @@ CINDEX_LINKAGE unsigned clang_CXXField_isMutable(CXCursor C);
49244924
*/
49254925
CINDEX_LINKAGE unsigned clang_CXXMethod_isDefaulted(CXCursor C);
49264926

4927+
/**
4928+
* Determine if a C++ method is declared '= delete'.
4929+
*/
4930+
CINDEX_LINKAGE unsigned clang_CXXMethod_isDeleted(CXCursor C);
4931+
49274932
/**
49284933
* Determine if a C++ member function or member function template is
49294934
* pure virtual.

clang/test/Index/availability.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ struct Foo {
99
// RUN: c-index-test -test-print-type --std=c++11 %s | FileCheck %s
1010
// CHECK: FunctionDecl=foo:1:6 (unavailable) [type=void ()] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
1111
// CHECK: StructDecl=Foo:3:8 (Definition) [type=Foo] [typekind=Record] [isPOD=1]
12-
// CHECK: CXXMethod=foo:4:7 (unavailable) [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
13-
// CHECK: CXXConstructor=Foo:5:3 (unavailable) (default constructor) [type=void (){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
12+
// CHECK: CXXMethod=foo:4:7 (unavailable) (deleted) [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
13+
// CHECK: CXXConstructor=Foo:5:3 (unavailable) (default constructor) (deleted) [type=void (){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]

clang/test/Index/deletion.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct Foo {
2+
int foo() = delete;
3+
int bar();
4+
Foo() = delete;
5+
Foo(int);
6+
};
7+
8+
9+
// RUN: c-index-test -test-print-type --std=c++11 %s | FileCheck %s
10+
// CHECK: StructDecl=Foo:1:8 (Definition) [type=Foo] [typekind=Record] [isPOD=1]
11+
// CHECK: CXXMethod=foo:2:7 (unavailable) (deleted) [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
12+
// CHECK: CXXMethod=bar:3:7 [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
13+
// CHECK: CXXConstructor=Foo:4:3 (unavailable) (default constructor) (deleted) [type=void (){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
14+
// CHECK: CXXConstructor=Foo:5:3 (converting constructor) [type=void (int){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [args= [int] [Int]] [isPOD=0]

clang/tools/c-index-test/c-index-test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,8 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) {
900900
printf(" (mutable)");
901901
if (clang_CXXMethod_isDefaulted(Cursor))
902902
printf(" (defaulted)");
903+
if (clang_CXXMethod_isDeleted(Cursor))
904+
printf(" (deleted)");
903905
if (clang_CXXMethod_isStatic(Cursor))
904906
printf(" (static)");
905907
if (clang_CXXMethod_isVirtual(Cursor))

clang/tools/libclang/CIndex.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8861,6 +8861,16 @@ unsigned clang_CXXMethod_isDefaulted(CXCursor C) {
88618861
return (Method && Method->isDefaulted()) ? 1 : 0;
88628862
}
88638863

8864+
unsigned clang_CXXMethod_isDeleted(CXCursor C) {
8865+
if (!clang_isDeclaration(C.kind))
8866+
return 0;
8867+
8868+
const Decl *D = cxcursor::getCursorDecl(C);
8869+
const CXXMethodDecl *Method =
8870+
D ? dyn_cast_if_present<CXXMethodDecl>(D->getAsFunction()) : nullptr;
8871+
return (Method && Method->isDeleted()) ? 1 : 0;
8872+
}
8873+
88648874
unsigned clang_CXXMethod_isStatic(CXCursor C) {
88658875
if (!clang_isDeclaration(C.kind))
88668876
return 0;

clang/tools/libclang/libclang.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ LLVM_16 {
409409
global:
410410
clang_getUnqualifiedType;
411411
clang_getNonReferenceType;
412+
clang_CXXMethod_isDeleted;
412413
};
413414

414415
# Example of how to add a new symbol version entry. If you do add a new symbol

0 commit comments

Comments
 (0)