// variadicTpl.cpp — Phase 2.7 cxxSmoke check 3.
//
// Exercises a variadic-template function with pack expansion.  The
// `sumAll` helper folds the integer pack via initializer-list expansion
// (the classic pre-C++17 pattern; the fold-expression variant is its own
// check, see foldExpr.cpp).
//
//   $025000 = 0x0078  (sum 0x10+0x20+0x30+0x18 = 0x78)
//   $025002 = 0x0099  success marker
#include <stdint.h>


template <typename... Ts>
static int sumAll(Ts... vs) {
    int s = 0;
    int dummy[] = { 0, ((s += vs), 0)... };
    (void)dummy;
    return s;
}


int main(void) {
    int r = sumAll(0x10, 0x20, 0x30, 0x18);
    *(volatile uint16_t *)0x025000UL = (uint16_t)r;
    *(volatile uint16_t *)0x025002UL = 0x0099;
    return 0;
}
