Commit Graph

3 Commits

Author SHA1 Message Date
William S Fulton 8c8e27d246 Add warning for ineffective %template instantiations
on forward template class declarations. A full template class definition is
required in order to wrap a template class as a proxy class.

Also tidyup handling of classforward code (no observable changes in
test-suite).
2024-06-29 17:36:46 +01:00
William S Fulton 0c56f3557e Improved error checking when defining classes and using %template.
1. When a template is instantiated via %template and uses the unary scope
operator ::, an error occurs if the instantiation is attempted within a
namespace that does not enclose the instantiated template.
For example, the following will now error as ::test::max is not enclosed within test1:

Error: '::test::max' resolves to 'test::max' and was incorrectly instantiated in
scope 'test1' instead of within scope 'test'.
  namespace test1 {
    %template(maxchar) ::test::max<char>;
  }

2. SWIG previously failed to always detect a template did not exist when using
%template. In particular when instantiating a global template incorrectly within
namespace. The code below now correctly emits an error:

Error: Template 'test5::GlobalVector' undefined.
  namespace test5 {
  }
  template<typename T> struct GlobalVector {};
  %template(GVI) test5::GlobalVector<int>;

3. Also error out if an attempt is made to define a class using the unary scope
operator ::. The following is not legal C++ and now results in an error:

Error: Using the unary scope operator :: in class definition '::Space2::B' is invalid.
  namespace Space2 {
    struct B;
  }
  struct ::Space2::B {};
2023-03-13 22:39:59 +00:00
William S Fulton 09af283371 Test a few %template errors 2017-08-16 00:24:25 +01:00