[clang] [libclang/python] Fix get_exception_specification_kind (PR #101548)

via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 1 12:07:04 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Jannick Kremer (DeinAlptraum)

<details>
<summary>Changes</summary>

This fixes a bug with `get_exception_ specification_kind`. The function did not work before. Also add a test that confirms that it works now.

---
Full diff: https://github.com/llvm/llvm-project/pull/101548.diff


2 Files Affected:

- (modified) clang/bindings/python/clang/cindex.py (+1-1) 
- (modified) clang/bindings/python/tests/cindex/test_exception_specification_kind.py (+5-2) 


``````````diff
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index 2038ef6045c7d..c251c46a04adf 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -2654,7 +2654,7 @@ def get_exception_specification_kind(self):
         the ExceptionSpecificationKind enumeration.
         """
         return ExceptionSpecificationKind.from_id(
-            conf.lib.clang.getExceptionSpecificationType(self)
+            conf.lib.clang_getExceptionSpecificationType(self)
         )
 
     @property
diff --git a/clang/bindings/python/tests/cindex/test_exception_specification_kind.py b/clang/bindings/python/tests/cindex/test_exception_specification_kind.py
index 8e2a6b5c50223..6653c22eaf9cd 100644
--- a/clang/bindings/python/tests/cindex/test_exception_specification_kind.py
+++ b/clang/bindings/python/tests/cindex/test_exception_specification_kind.py
@@ -13,7 +13,7 @@
 
 def find_function_declarations(node, declarations=[]):
     if node.kind == clang.cindex.CursorKind.FUNCTION_DECL:
-        declarations.append((node.spelling, node.exception_specification_kind))
+        declarations.append(node)
     for child in node.get_children():
         declarations = find_function_declarations(child, declarations)
     return declarations
@@ -33,4 +33,7 @@ def test_exception_specification_kind(self):
             ("square2", ExceptionSpecificationKind.BASIC_NOEXCEPT),
             ("square3", ExceptionSpecificationKind.COMPUTED_NOEXCEPT),
         ]
-        self.assertListEqual(declarations, expected)
+        from_cursor = [(node.spelling, node.exception_specification_kind) for node in declarations]
+        from_type = [(node.spelling, node.type.get_exception_specification_kind()) for node in declarations]
+        self.assertListEqual(from_cursor, expected)
+        self.assertListEqual(from_type, expected)

``````````

</details>


https://github.com/llvm/llvm-project/pull/101548


More information about the cfe-commits mailing list