Forward declaration of class used in template function is not compiled by clang++

前端 未结 4 902
半阙折子戏
半阙折子戏 2021-02-13 22:53

There is this code:

class A;

template 
void fun() {
   A a;
}

class A { 
public: 
   A() {  } 
};

int main() { 
   fun(); 
   return         


        
4条回答
  •  遥遥无期
    2021-02-13 23:05

    Clang is correct, as far as I know. At your function fun, you do not know the size of A, and since your allocating an A, you need to know it's size. In my opinion, gcc is way to forgiving here.

提交回复
热议问题