相关疑难解决方法(0)

非实例化C++模板函数的语义正确性

以下C++代码无法编译,例如使用g ++ - 4.7或clang ++ - 3.2:

struct Bar {};

template<typename T>
void foo(T t, Bar bar) {
    t.compiler_does_not_care();
    bar.nonexistent_method();
}

int main() {}
Run Code Online (Sandbox Code Playgroud)

为什么编译器检查模板函数foo的代码是否具有语义正确性(他们可以在哪里),即使它从未实例化过?这个标准是否合规?

c++ templates instantiation

5
推荐指数
1
解决办法
175
查看次数

标签 统计

c++ ×1

instantiation ×1

templates ×1