Tag: if constexpr

为什么这个“未定义的外部variables”导致C ++ 17中的链接器错误?

我已经编译并在C ++ 17编译器(Coliru)中运行以下程序。 在程序中,我宣布了一个externvariables,但没有定义它。 但是,编译器不会给出链接器错误 。 #include <iostream> extern int i; // Only declaration int func() { if constexpr (true) return 0; else if (i) return i; else return -1; } int main() { int ret = func(); std::cout<<"Ret : "<<ret<<std::endl; } 为什么编译器不提供链接器错误?