xref: /llvm-project-15.0.7/clang/bindings/python/tests/cindex/test_exception_specification_kind.py (revision 409fb368)
  • Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import clang.cindex
2from clang.cindex import ExceptionSpecificationKind
3from .util import get_tu
4
5import unittest
6
7
8def find_function_declarations(node, declarations=[]):
9    if node.kind == clang.cindex.CursorKind.FUNCTION_DECL:
10        declarations.append((node.spelling, node.exception_specification_kind))
11    for child in node.get_children():
12        declarations = find_function_declarations(child, declarations)
13    return declarations
14
15
16class TestExceptionSpecificationKind(unittest.TestCase):
17    def test_exception_specification_kind(self):
18        source = """int square1(int x);
19                    int square2(int x) noexcept;
20                    int square3(int x) noexcept(noexcept(x * x));"""
21
22        tu = get_tu(source, lang='cpp', flags=['-std=c++14'])
23
24        declarations = find_function_declarations(tu.cursor)
25        expected = [
26            ('square1', ExceptionSpecificationKind.NONE),
27            ('square2', ExceptionSpecificationKind.BASIC_NOEXCEPT),
28            ('square3', ExceptionSpecificationKind.COMPUTED_NOEXCEPT)
29        ]
30        self.assertListEqual(declarations, expected)
31

served by {OpenGrok

Last Index Update: Fri May 15 20:09:11 GMT 2026