2 from clang
.cindex
import Config
4 if "CLANG_LIBRARY_PATH" in os
.environ
:
5 Config
.set_library_path(os
.environ
["CLANG_LIBRARY_PATH"])
8 from clang
.cindex
import ExceptionSpecificationKind
9 from .util
import get_tu
14 def find_function_declarations(node
, declarations
=[]):
15 if node
.kind
== clang
.cindex
.CursorKind
.FUNCTION_DECL
:
16 declarations
.append((node
.spelling
, node
.exception_specification_kind
))
17 for child
in node
.get_children():
18 declarations
= find_function_declarations(child
, declarations
)
22 class TestExceptionSpecificationKind(unittest
.TestCase
):
23 def test_exception_specification_kind(self
):
24 source
= """int square1(int x);
25 int square2(int x) noexcept;
26 int square3(int x) noexcept(noexcept(x * x));"""
28 tu
= get_tu(source
, lang
="cpp", flags
=["-std=c++14"])
30 declarations
= find_function_declarations(tu
.cursor
)
32 ("square1", ExceptionSpecificationKind
.NONE
),
33 ("square2", ExceptionSpecificationKind
.BASIC_NOEXCEPT
),
34 ("square3", ExceptionSpecificationKind
.COMPUTED_NOEXCEPT
),
36 self
.assertListEqual(declarations
, expected
)