Skip to content

Commit ba64eaa

Browse files
committed
Added support for P2662r3.
1 parent da1e5ec commit ba64eaa

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

CodeGenerator.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,6 +2112,23 @@ void CodeGenerator::InsertArg(const CXXFoldExpr* stmt)
21122112
}
21132113
//-----------------------------------------------------------------------------
21142114

2115+
void CodeGenerator::InsertArg(const PackIndexingExpr* stmt)
2116+
{
2117+
if(stmt->isFullySubstituted()) {
2118+
const auto* constExpr = dyn_cast_or_null<ConstantExpr>(stmt->getIndexExpr());
2119+
2120+
mOutputFormatHelper.Append(BuildInternalVarName(GetName(*stmt->getPackDecl())),
2121+
constExpr->getAPValueResult().getInt());
2122+
2123+
} else {
2124+
mOutputFormatHelper.Append(GetName(*stmt->getPackDecl()), "...[");
2125+
2126+
InsertArg(stmt->getIndexExpr());
2127+
mOutputFormatHelper.Append("]");
2128+
}
2129+
}
2130+
//-----------------------------------------------------------------------------
2131+
21152132
void CodeGenerator::InsertArg(const CXXInheritedCtorInitExpr* stmt)
21162133
{
21172134
const auto& constructorDecl = *stmt->getConstructor();

CodeGeneratorTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ SUPPORTED_STMT(SourceLocExpr)
136136
SUPPORTED_STMT(CXXParenListInitExpr)
137137
SUPPORTED_STMT(CppInsightsCommentStmt)
138138
SUPPORTED_STMT(CXXPseudoDestructorExpr)
139+
SUPPORTED_STMT(PackIndexingExpr)
139140

140141
#undef IGNORED_DECL
141142
#undef IGNORED_STMT

tests/p2662Test.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// cmdline:-std=c++26
2+
3+
template<typename... T>
4+
constexpr auto first_plus_last(T... values) -> T...[0]
5+
{
6+
return T...[0](values...[0] + values...[sizeof...(values) - 1]);
7+
}
8+
9+
// first_plus_last(); // ill formed
10+
static_assert(first_plus_last(1, 2, 10) == 11);
11+
12+
auto res = [](auto... pack) {
13+
decltype(pack...[0]) x5; // type is int
14+
decltype((pack...[0])) x6{x5}; // type is int&
15+
16+
return 0;
17+
}(0, 3.14, 'c');
18+
19+
int main() {}
20+

tests/p2662Test.expect

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
template<typename ... T>
2+
inline constexpr T...[0] first_plus_last(T... values)
3+
{
4+
return T...[0](values...[0] + values...[sizeof...(values) - 1]);
5+
}
6+
7+
/* First instantiated from: p2662Test.cpp:10 */
8+
#ifdef INSIGHTS_USE_TEMPLATE
9+
template<>
10+
inline constexpr int first_plus_last<int, int, int>(int __values0, int __values1, int __values2)
11+
{
12+
return int(__values0 + __values2);
13+
}
14+
#endif
15+
16+
17+
/* PASSED: static_assert(first_plus_last(1, 2, 10) == 11); */
18+
19+
20+
class __lambda_12_12
21+
{
22+
public:
23+
template<class ... type_parameter_0_0>
24+
inline /*constexpr */ auto operator()(type_parameter_0_0... pack) const
25+
{
26+
decltype(pack...[0]) x5;
27+
decltype((pack...[0])) x6 = {x5};
28+
return 0;
29+
}
30+
31+
#ifdef INSIGHTS_USE_TEMPLATE
32+
template<>
33+
inline /*constexpr */ int operator()<int, double, char>(int __pack0, double __pack1, char __pack2) const
34+
{
35+
int x5;
36+
int & x6 = {x5};
37+
return 0;
38+
}
39+
#endif
40+
41+
private:
42+
template<class ... type_parameter_0_0>
43+
static inline /*constexpr */ auto __invoke(type_parameter_0_0... pack)
44+
{
45+
return __lambda_12_12{}.operator()<type_parameter_0_0... >(pack...);
46+
}
47+
48+
public:
49+
// /*constexpr */ __lambda_12_12() = default;
50+
51+
} __lambda_12_12{};
52+
53+
int res = __lambda_12_12.operator()(0, 3.1400000000000001, 'c');
54+
55+
int main()
56+
{
57+
return 0;
58+
}

0 commit comments

Comments
 (0)