[clang] bc14ed7 - Add clang_CXXMethod_isDeleted function
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 21 08:13:36 PDT 2022
Author: Anders Langlands
Date: 2022-09-21T11:12:48-04:00
New Revision: bc14ed7de0f1f038c500b5f1d6c7a86a4a2d4527
URL: https://github.com/llvm/llvm-project/commit/bc14ed7de0f1f038c500b5f1d6c7a86a4a2d4527
DIFF: https://github.com/llvm/llvm-project/commit/bc14ed7de0f1f038c500b5f1d6c7a86a4a2d4527.diff
LOG: 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
Added:
clang/test/Index/deletion.cpp
Modified:
clang/bindings/python/clang/cindex.py
clang/docs/ReleaseNotes.rst
clang/include/clang-c/Index.h
clang/test/Index/availability.cpp
clang/tools/c-index-test/c-index-test.c
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/libclang.map
Removed:
################################################################################
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index 89063dd40155b..a8fe6e3e7ed56 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -1473,6 +1473,12 @@ def is_default_method(self):
"""
return conf.lib.clang_CXXMethod_isDefaulted(self)
+ def is_deleted_method(self):
+ """Returns True if the cursor refers to a C++ member function or member
+ function template that is declared '= delete'.
+ """
+ return conf.lib.clang_CXXMethod_isDeleted(self)
+
def is_mutable_field(self):
"""Returns True if the cursor refers to a C++ field that is declared
'mutable'.
@@ -3426,6 +3432,10 @@ def cursor(self):
[Cursor],
bool),
+ ("clang_CXXMethod_isDeleted",
+ [Cursor],
+ bool),
+
("clang_CXXMethod_isPureVirtual",
[Cursor],
bool),
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 372661814ab9a..258884cd2ba34 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -398,6 +398,8 @@ libclang
the behavior of ``QualType::getUnqualifiedType`` for ``CXType``.
- Introduced the new function ``clang_getNonReferenceType``, which mimics
the behavior of ``QualType::getNonReferenceType`` for ``CXType``.
+- Introduced the new function ``clang_CXXMethod_isDeleted``, which queries
+ whether the method is declared ``= delete``.
Static Analyzer
---------------
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index c0dbad869114b..a9810aa4cf9d0 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -4924,6 +4924,11 @@ CINDEX_LINKAGE unsigned clang_CXXField_isMutable(CXCursor C);
*/
CINDEX_LINKAGE unsigned clang_CXXMethod_isDefaulted(CXCursor C);
+/**
+ * Determine if a C++ method is declared '= delete'.
+ */
+CINDEX_LINKAGE unsigned clang_CXXMethod_isDeleted(CXCursor C);
+
/**
* Determine if a C++ member function or member function template is
* pure virtual.
diff --git a/clang/test/Index/availability.cpp b/clang/test/Index/availability.cpp
index d8cd3bfb65414..05963b09ad478 100644
--- a/clang/test/Index/availability.cpp
+++ b/clang/test/Index/availability.cpp
@@ -9,5 +9,5 @@ struct Foo {
// RUN: c-index-test -test-print-type --std=c++11 %s | FileCheck %s
// CHECK: FunctionDecl=foo:1:6 (unavailable) [type=void ()] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
// CHECK: StructDecl=Foo:3:8 (Definition) [type=Foo] [typekind=Record] [isPOD=1]
-// CHECK: CXXMethod=foo:4:7 (unavailable) [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
-// CHECK: CXXConstructor=Foo:5:3 (unavailable) (default constructor) [type=void (){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
+// CHECK: CXXMethod=foo:4:7 (unavailable) (deleted) [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
+// CHECK: CXXConstructor=Foo:5:3 (unavailable) (default constructor) (deleted) [type=void (){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
diff --git a/clang/test/Index/deletion.cpp b/clang/test/Index/deletion.cpp
new file mode 100644
index 0000000000000..aa5e869a86288
--- /dev/null
+++ b/clang/test/Index/deletion.cpp
@@ -0,0 +1,14 @@
+struct Foo {
+ int foo() = delete;
+ int bar();
+ Foo() = delete;
+ Foo(int);
+};
+
+
+// RUN: c-index-test -test-print-type --std=c++11 %s | FileCheck %s
+// CHECK: StructDecl=Foo:1:8 (Definition) [type=Foo] [typekind=Record] [isPOD=1]
+// CHECK: CXXMethod=foo:2:7 (unavailable) (deleted) [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
+// CHECK: CXXMethod=bar:3:7 [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
+// CHECK: CXXConstructor=Foo:4:3 (unavailable) (default constructor) (deleted) [type=void (){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
+// CHECK: CXXConstructor=Foo:5:3 (converting constructor) [type=void (int){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [args= [int] [Int]] [isPOD=0]
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c
index 8eac69de3f1a2..901ab8273a76c 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -900,6 +900,8 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) {
printf(" (mutable)");
if (clang_CXXMethod_isDefaulted(Cursor))
printf(" (defaulted)");
+ if (clang_CXXMethod_isDeleted(Cursor))
+ printf(" (deleted)");
if (clang_CXXMethod_isStatic(Cursor))
printf(" (static)");
if (clang_CXXMethod_isVirtual(Cursor))
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index b3f91ef794ba2..22f2f7d482d9d 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -8861,6 +8861,16 @@ unsigned clang_CXXMethod_isDefaulted(CXCursor C) {
return (Method && Method->isDefaulted()) ? 1 : 0;
}
+unsigned clang_CXXMethod_isDeleted(CXCursor C) {
+ if (!clang_isDeclaration(C.kind))
+ return 0;
+
+ const Decl *D = cxcursor::getCursorDecl(C);
+ const CXXMethodDecl *Method =
+ D ? dyn_cast_if_present<CXXMethodDecl>(D->getAsFunction()) : nullptr;
+ return (Method && Method->isDeleted()) ? 1 : 0;
+}
+
unsigned clang_CXXMethod_isStatic(CXCursor C) {
if (!clang_isDeclaration(C.kind))
return 0;
diff --git a/clang/tools/libclang/libclang.map b/clang/tools/libclang/libclang.map
index 911292a81c27b..2d7c2e2c8da62 100644
--- a/clang/tools/libclang/libclang.map
+++ b/clang/tools/libclang/libclang.map
@@ -409,6 +409,7 @@ LLVM_16 {
global:
clang_getUnqualifiedType;
clang_getNonReferenceType;
+ clang_CXXMethod_isDeleted;
};
# Example of how to add a new symbol version entry. If you do add a new symbol
More information about the cfe-commits
mailing list