open-watcom / open-watcom-v2

Open Watcom V2.0 - Source code repository, Wiki, Latest Binary build, Archived builds including all installers for download.
Other
983 stars 160 forks source link

Can’t compile template class declared in namespace defined outside namespace #278

Open Mazdaywik opened 8 years ago

Mazdaywik commented 8 years ago

If template class declared in namespace, but defined outside namespace, Open Watcom can’t compile it. For example:

namespace ns {

  // declaration of class
  template <typename T>
  class Templ;

}

// definition of class
template <typename T>
class ns::Templ {
public:
  T value;
};

ns::Templ<int> x;

int f() {
  return ++x.value;
}
Open Watcom C/C++ CL Clone for 386
Version 2.0 beta Apr  2 2015 11:27:33 (32-bit)
… copyrights …
test-don’t-work.cpp
test-don’t-work.cpp(11): Error! E121: col(17) syntax error
test-don’t-work.cpp(16): Error! E326: col(17) defining 'x' is not possible because its type has unknown size
test-don’t-work.cpp(16): Note! N392: col(16) definition: 'ns::Templ<int> x'
test-don’t-work.cpp(19): Error! E516: col(12) class for object is not defined
test-don’t-work.cpp(19): Note! N638: col(12) 'Templ' defined in: test-don’t-work.cpp(5) (col 9)
test-don’t-work.cpp(19): Note! N638: col(12) 'Templ' defined in: test-don’t-work.cpp(5) (col 9)

This code is successfully compiled by BCC 5.5, Visual C++ 18.00.40629, GCC (g++) 4.8.1, CLang 3.7.0.

test-don’t-work.cpp test-don’t-work.err

jmalak commented 8 years ago

Thanks for your bug report. OW C++ compiler need to improve support for name spaces and templates.