http://gcc.gnu.org/bugzilla/show_bug.cgi?id=99
--- Comment #20 from Manuel López-Ibáñez <manu at gcc dot gnu.org> --- (In reply to Wolfgang Bangerth from comment #11) > Here's another very nice example from PR 20313: > ------------------------- > template<int j> struct s; > template<int i> s<i>::s(int j) {} > ------------------------- > Note that the definition of the constructor is invalid because the struct > isn't complete. Here's what we get: > g/x> /home/bangerth/bin/gcc-4.0-pre/bin/c++ -c x.cc > x.cc:2: error: invalid use of undefined type ?struct s<j>? > x.cc:1: error: declaration of ?struct s<j>? > x.cc:2: error: template definition of non-template ?s<j>::s(int)? > > Note how the compiler uses the template argument 'j', although we use > template argument 'i' in line 2! I have been doing a bit more analysis and it is not very clear what would be the correct output in this example. For the slightly different testcase: template<int x> struct s; template<int i> s<i>::s(int j) {} GCC 4.9 prints: /home/manuel/test1/pr99.cc:2:30: error: invalid use of incomplete type ‘struct s<x>’ template<int i> s<i>::s(int j) {} ^ /home/manuel/test1/pr99.cc:1:24: error: declaration of ‘struct s<x>’ template<int x> struct s; ^ If we do this change: Index: pt.c =================================================================== --- pt.c (revision 209347) +++ pt.c (working copy) @@ -7574,10 +7574,11 @@ lookup_template_class_1 (tree d1, tree a class, however, such a reference is an instantiation. */ if ((entering_scope || !PRIMARY_TEMPLATE_P (gen_tmpl) || currently_open_class (template_type)) /* comp_template_args is expensive, check it last. */ + && false && comp_template_args (TYPE_TI_ARGS (template_type), arglist)) return template_type; /* If we already have this specialization, return it. */ then it prints: /home/manuel/test1/pr99.cc:2:30: error: invalid use of incomplete type ‘struct s<i>’ template<int i> s<i>::s(int j) {} ^ /home/manuel/test1/pr99.cc:1:24: error: declaration of ‘struct s<i>’ template<int x> struct s; ^ I am not sure one output is better than the other.