Does nvcc support fold expression in C++17?

Hello,

I’m writing a variadic template function like:

template <typename... PayloadTypes>
RT_DEVICE_FUNCTION void getPayloads(PayloadTypes*... payloads) {
    constexpr size_t numDwords = detail::calcSumDwords<PayloadTypes...>();
    ...
}

, where detail::calcSumDwords<>() is a function to get the total size of template parameters.

template <typename HeadType, typename... TailTypes>
RT_DEVICE_FUNCTION constexpr size_t _calcSumDwords() {
    uint32_t ret = sizeof(HeadType) / sizeof(uint32_t);
    if constexpr (sizeof...(TailTypes) > 0)
        ret += _calcSumDwords<TailTypes...>();
    return ret;
}

template <typename... PayloadTypes>
RT_DEVICE_FUNCTION constexpr size_t calcSumDwords() {
    if constexpr (sizeof...(PayloadTypes) > 0)
        return _calcSumDwords<PayloadTypes...>();
    else
        return 0;
}

The programming guide says the latest nvcc supports C++17 features:

All C++17 language features are supported in nvcc version 11.0 and later, subject to restrictions described here.

I thought that calcDwords() can be replaced by simpler fold expression in C++17 like

constexpr size_t numDwords = (sizeof(PayloadTypes) + ...);

but got errors:

error : expected an expression
parameter pack “PayloadTypes” was referenced but not expanded

Does nvcc supports fold expression in C++17?

Thanks

It seems to work for the case I constructed out of what you have shown:

$ cat t17.cu
#include <iostream>
#include <cstdio>

#define RT_DEVICE_FUNCTION __host__ __device__

template <typename HeadType, typename... TailTypes>
RT_DEVICE_FUNCTION constexpr size_t _calcSumDwords() {
    uint32_t ret = sizeof(HeadType) / sizeof(uint32_t);
    if constexpr (sizeof...(TailTypes) > 0)
        ret += _calcSumDwords<TailTypes...>();
    return ret;
}

template <typename... PayloadTypes>
RT_DEVICE_FUNCTION constexpr size_t calcSumDwords() {
    if constexpr (sizeof...(PayloadTypes) > 0)
        return _calcSumDwords<PayloadTypes...>();
    else
        return 0;
}

template <typename... PayloadTypes>
RT_DEVICE_FUNCTION void getPayloads(PayloadTypes*... payloads) {
    //constexpr size_t numDwords = calcSumDwords<PayloadTypes...>();
    constexpr size_t numDwords = (sizeof(PayloadTypes) + ...);
    printf("%lu\n", numDwords);
}
__global__ void k(){
        int data[] = {0};
        getPayloads(data);
}
int main(){
        int data[] = {0};
        getPayloads(data);
        k<<<1,1>>>();
        cudaDeviceSynchronize();
}
$ nvcc -o t17 t17.cu -std=c++17
$ cuda-memcheck ./t17
========= CUDA-MEMCHECK
4
4
========= ERROR SUMMARY: 0 errors
$

Sorry, I noticed that I need to specify -std=c++17 for the case where the host compiler is MSVC 16.7.6.