if-constexpr,编译报错expected a “(“
我的情况:vs 2017, nvcc, c++ 17, cuda c/c++ 混合编程
从在网上搜索到的结果看来是编译器的编译问题。
C++17 constexpr-if compiles but is highlighted as an error - Developer Community
g++ - C++17 refuses to compile example if constexpr giving expected ‘(’ before ‘constexpr’ - Stack Overflow
结论:属性页中,C/C++的c++语言标准要设置为ISO C++17标准,此外,cuda c/c++也要设置使用c++17编译。CUDA C/C++ -> Command line -> 其它选项,添加一行 -std=c++17 -Xcompiler "/std:c++17"
c++ - How to enable C++17 code generation in VS2019 CUDA project - Stack Overflow
2025.7.13