105 lines
3.7 KiB
Python
105 lines
3.7 KiB
Python
def test_constinit_consteval() -> None:
|
|
content = """
|
|
struct S
|
|
{
|
|
static constinit int i = 5;
|
|
|
|
static consteval int func(int i) { return i*i; }
|
|
};
|
|
|
|
template<std::size_t numBits>
|
|
consteval auto getUintType()
|
|
{
|
|
if constexpr (numBits == 8) {
|
|
return std::uint8_t{};
|
|
}
|
|
else if constexpr (numBits == 16) {
|
|
return std::uint16_t{};
|
|
}
|
|
else if constexpr (numBits == 32) {
|
|
return std::uint32_t{};
|
|
}
|
|
else if constexpr (numBits == 64) {
|
|
return std::uint64_t{};
|
|
}
|
|
}
|
|
"""
|
|
data = parse_string(content, cleandoc=True)
|
|
|
|
assert data == ParsedData(
|
|
namespace=NamespaceScope(
|
|
classes=[
|
|
ClassScope(
|
|
class_decl=ClassDecl(
|
|
typename=PQName(
|
|
segments=[NameSpecifier(name="S")], classkey="struct"
|
|
)
|
|
),
|
|
fields=[
|
|
Field(
|
|
access="public",
|
|
type=Type(
|
|
typename=PQName(
|
|
segments=[FundamentalSpecifier(name="int")]
|
|
)
|
|
),
|
|
name="i",
|
|
value=Value(tokens=[Token(value="5")]),
|
|
constinit=True,
|
|
static=True,
|
|
)
|
|
],
|
|
methods=[
|
|
Method(
|
|
return_type=Type(
|
|
typename=PQName(
|
|
segments=[FundamentalSpecifier(name="int")]
|
|
)
|
|
),
|
|
name=PQName(segments=[NameSpecifier(name="func")]),
|
|
parameters=[
|
|
Parameter(
|
|
type=Type(
|
|
typename=PQName(
|
|
segments=[FundamentalSpecifier(name="int")]
|
|
)
|
|
),
|
|
name="i",
|
|
)
|
|
],
|
|
consteval=True,
|
|
static=True,
|
|
has_body=True,
|
|
access="public",
|
|
)
|
|
],
|
|
)
|
|
],
|
|
functions=[
|
|
Function(
|
|
return_type=Type(typename=PQName(segments=[AutoSpecifier()])),
|
|
name=PQName(segments=[NameSpecifier(name="getUintType")]),
|
|
parameters=[],
|
|
consteval=True,
|
|
has_body=True,
|
|
template=TemplateDecl(
|
|
params=[
|
|
TemplateNonTypeParam(
|
|
type=Type(
|
|
typename=PQName(
|
|
segments=[
|
|
NameSpecifier(name="std"),
|
|
NameSpecifier(name="size_t"),
|
|
]
|
|
)
|
|
),
|
|
name="numBits",
|
|
)
|
|
]
|
|
),
|
|
)
|
|
],
|
|
)
|
|
)
|
|
|