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

前端 未结 4 903
半阙折子戏
半阙折子戏 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:18

    Comeau's compiler does not like it either:

    "ComeauTest.c", line 5: error: incomplete type is not allowed
         A a;
           ^
    

    However my attempts at finding chapter and verse in the C++ standard were fruitless. It seems hidden in between the lines and interactions of "point of instantiation", "name resolution". Paragraphs 14.6/8 and 14.6/9 of the 2003 standard seem relevant.

提交回复
热议问题