http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49198
Summary: GCC trunk and 4.6 generate spurious "has incomplete type" errors Product: gcc Version: 4.6.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: a...@gcc.gnu.org Created attachment 24376 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24376 Minimal reproduction See the attached tst.cc file. When compiled with GCC trunk and 4.6, it generates the following errors: tst.cc: In instantiation of ‘S<IC>’: tst.cc:14:7: instantiated from here tst.cc:3:32: error: ‘S<T>::t’ has incomplete type tst.cc:1:7: error: forward declaration of ‘struct IC’ However, the code is structured such that IC need not be complete. According to the C++ standard (14.7.1): "Unless a class template specialization has been explicitly instantiated (14.7.2) or explicitly specialized (14.7.3), the class template specialization is implicitly instantiated when the specialization is referenced in a context that requires a completely-defined object type or when the completeness of the class type affects the semantics of the program." In this case, we only refer to S<IC>* (pointer), which does not require a complete type. Therefore, the class template specialization S<IC> should not be instantiated, and IC need not be complete. Various trivial modifications to this program (e.g. replacing S<IC>* with IC* or replacing FT(F) with F) do not generate an error. Nor does GCC 4.4.3.