diff --git a/include/cppast/cpp_variable.hpp b/include/cppast/cpp_variable.hpp index 3851f9c..42afe26 100644 --- a/include/cppast/cpp_variable.hpp +++ b/include/cppast/cpp_variable.hpp @@ -14,6 +14,7 @@ namespace cppast /// A [cppast::cpp_entity]() modelling a C++ variable. /// \notes This is not a member variable, /// use [cppast::cpp_member_variable]() for that. + /// But it can be `static` member variable. class cpp_variable final : public cpp_entity, public cpp_variable_base { public: diff --git a/test/cpp_variable.cpp b/test/cpp_variable.cpp index 90cf130..51c75e7 100644 --- a/test/cpp_variable.cpp +++ b/test/cpp_variable.cpp @@ -109,3 +109,37 @@ static struct {} l; }); REQUIRE(count == 12u); } + +TEST_CASE("static cpp_variable") +{ + auto code = R"( +struct test +{ + static int a; + static const int b; + static thread_local int c; +}; +)"; + + auto file = parse({}, "static_cpp_variable.cpp", code); + auto count = test_visit(*file, [&](const cpp_variable& var) { + REQUIRE(!var.default_value()); + REQUIRE(!var.is_constexpr()); + REQUIRE(is_static(var.storage_class())); + + if (var.name() == "a") + REQUIRE(equal_types({}, var.type(), *cpp_builtin_type::build("int"))); + else if (var.name() == "b") + REQUIRE(equal_types({}, var.type(), + *cpp_cv_qualified_type::build(cpp_builtin_type::build("int"), + cpp_cv_const))); + else if (var.name() == "c") + { + REQUIRE(equal_types({}, var.type(), *cpp_builtin_type::build("int"))); + REQUIRE(is_thread_local(var.storage_class())); + } + else + REQUIRE(false); + }); + REQUIRE(count == 3u); +}