Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2112,6 +2112,23 @@ void CodeGenerator::InsertArg(const CXXFoldExpr* stmt)
}
//-----------------------------------------------------------------------------

void CodeGenerator::InsertArg(const PackIndexingExpr* stmt)
{
if(stmt->isFullySubstituted()) {
const auto* constExpr = dyn_cast_or_null<ConstantExpr>(stmt->getIndexExpr());

mOutputFormatHelper.Append(BuildInternalVarName(GetName(*stmt->getPackDecl())),
constExpr->getAPValueResult().getInt());

} else {
mOutputFormatHelper.Append(GetName(*stmt->getPackDecl()), "...[");

InsertArg(stmt->getIndexExpr());
mOutputFormatHelper.Append("]");
}
}
//-----------------------------------------------------------------------------

void CodeGenerator::InsertArg(const CXXInheritedCtorInitExpr* stmt)
{
const auto& constructorDecl = *stmt->getConstructor();
Expand Down
1 change: 1 addition & 0 deletions CodeGeneratorTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ SUPPORTED_STMT(SourceLocExpr)
SUPPORTED_STMT(CXXParenListInitExpr)
SUPPORTED_STMT(CppInsightsCommentStmt)
SUPPORTED_STMT(CXXPseudoDestructorExpr)
SUPPORTED_STMT(PackIndexingExpr)

#undef IGNORED_DECL
#undef IGNORED_STMT
Expand Down
20 changes: 20 additions & 0 deletions tests/p2662Test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// cmdline:-std=c++26

template<typename... T>
constexpr auto first_plus_last(T... values) -> T...[0]
{
return T...[0](values...[0] + values...[sizeof...(values) - 1]);
}

// first_plus_last(); // ill formed
static_assert(first_plus_last(1, 2, 10) == 11);

auto res = [](auto... pack) {
decltype(pack...[0]) x5; // type is int
decltype((pack...[0])) x6{x5}; // type is int&

return 0;
}(0, 3.14, 'c');

int main() {}

58 changes: 58 additions & 0 deletions tests/p2662Test.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
template<typename ... T>
inline constexpr T...[0] first_plus_last(T... values)
{
return T...[0](values...[0] + values...[sizeof...(values) - 1]);
}

/* First instantiated from: p2662Test.cpp:10 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
inline constexpr int first_plus_last<int, int, int>(int __values0, int __values1, int __values2)
{
return int(__values0 + __values2);
}
#endif


/* PASSED: static_assert(first_plus_last(1, 2, 10) == 11); */


class __lambda_12_12
{
public:
template<class ... type_parameter_0_0>
inline /*constexpr */ auto operator()(type_parameter_0_0... pack) const
{
decltype(pack...[0]) x5;
decltype((pack...[0])) x6 = {x5};
return 0;
}

#ifdef INSIGHTS_USE_TEMPLATE
template<>
inline /*constexpr */ int operator()<int, double, char>(int __pack0, double __pack1, char __pack2) const
{
int x5;
int & x6 = {x5};
return 0;
}
#endif

private:
template<class ... type_parameter_0_0>
static inline /*constexpr */ auto __invoke(type_parameter_0_0... pack)
{
return __lambda_12_12{}.operator()<type_parameter_0_0... >(pack...);
}

public:
// /*constexpr */ __lambda_12_12() = default;

} __lambda_12_12{};

int res = __lambda_12_12.operator()(0, 3.1400000000000001, 'c');

int main()
{
return 0;
}