swig/Source/Swig
William S Fulton 959e627208 %template scope enforcement and class definition fixes
The scoping rules around %template have been specified and enforced.
The %template directive for a class template is the equivalent to an
explicit instantiation of a C++ class template. The scope for a valid
%template instantiation is now the same as the scope required for a
valid explicit instantiation of a C++ template. A definition of the
template for the explicit instantiation must be in scope where the
instantiation is declared and must not be enclosed within a different
namespace.

For example, a few %template and explicit instantiations of std::vector
are shown below:

  // valid
  namespace std {
    %template(vin) vector<int>;
    template class vector<int>;
  }

  // valid
  using namespace std;
  %template(vin) vector<int>;
  template class vector<int>;

  // valid
  using std::vector;
  %template(vin) vector<int>;
  template class vector<int>;

  // ill-formed
  namespace unrelated {
    using std::vector;
    %template(vin) vector<int>;
    template class vector<int>;
  }

  // ill-formed
  namespace unrelated {
    using namespace std;
    %template(vin) vector<int>;
    template class vector<int>;
  }

  // ill-formed
  namespace unrelated {
    namespace std {
      %template(vin) vector<int>;
      template class vector<int>;
    }
  }

  // ill-formed
  namespace unrelated {
    %template(vin) std::vector<int>;
    template class std::vector<int>;
  }

When the scope is incorrect, an error now occurs such as:

cpp_template_scope.i:34: Error: 'vector' resolves to 'std::vector' and
was incorrectly instantiated in scope 'unrelated' instead of within scope 'std'.

Previously SWIG accepted the ill-formed examples above but this led to
numerous subtle template scope problems especially in the presence of
using declarations and using directives as well as with %feature and %typemap.

Actually, a valid instantiation is one which conforms to the C++03
standard as C++11 made a change to disallow using declarations and
using directives to find a template.

  // valid C++03, ill-formed C++11
  using std::vector;
  template class vector<int>;

Similar fixes for defining classes using forward class references have
also been put in place. For example:

namespace Space1 {
  struct A;
}
namespace Space2 {
  struct Space1::A {
    void x();
  }
}

will now error out with:

cpp_class_definition.i:5: Error: 'Space1::A' resolves to 'Space1::A' and
was incorrectly instantiated in scope 'Space2' instead of within scope 'Space1'.
2017-08-16 00:24:25 +01:00
..
cwrap.c Partial support for %constant and structs 2014-12-18 07:01:08 +00:00
deprecate.c Remove cvs/svn Id strings 2013-01-12 01:21:16 +00:00
error.c Make sure warning and error messages are not split up 2017-06-16 19:24:48 +01:00
extend.c Create separate extetnd.c file for handling extensions / %extend 2014-05-21 19:16:15 +01:00
fragment.c Fix missing fragment name in warning message about missing fragment 2014-02-22 01:04:50 +00:00
getopt.c Remove cvs/svn Id strings 2013-01-12 01:21:16 +00:00
include.c Fix leaked file descriptor 2016-06-16 15:53:22 +03:00
misc.c %template scope enforcement and class definition fixes 2017-08-16 00:24:25 +01:00
naming.c Suppress incorrect warning when a keyword is used in template classes 2016-12-20 19:44:57 +00:00
parms.c Remove cvs/svn Id strings 2013-01-12 01:21:16 +00:00
scanner.c Fix seg fault parsing unterminated raw string literals 2017-02-09 22:02:20 +00:00
stype.c Fix wrapping of references/pointers and qualifiers to member pointers 2017-03-16 21:04:38 +00:00
swig.h %template scope enforcement and class definition fixes 2017-08-16 00:24:25 +01:00
swigfile.h Fix segfaults when using filename paths greater than 1024 characters in length - use String * and heap instead of fixed size static char array buffers. 2012-11-18 00:45:18 +00:00
swigopt.h merge revisions 11872:11876 from trunk to gsoc2009-matevz branch - license changes 2010-03-06 00:51:54 +00:00
swigparm.h Fix some subtle named output typemap lookup misses, the fully qualified name was not always being in all cases such as member variables 2012-11-13 22:16:28 +00:00
swigscan.h Nested classes support 2013-11-29 07:02:34 +00:00
swigtree.h Minor code improvements 2013-11-29 07:33:55 +00:00
swigwrap.h merge revisions 11872:11876 from trunk to gsoc2009-matevz branch - license changes 2010-03-06 00:51:54 +00:00
symbol.c using 2-level caching as suggested by @wsfulton 2017-01-09 09:46:33 -06:00
tree.c Show node pointer value when displaying a node tree 2015-10-10 15:19:52 +01:00
typemap.c Typemap change for templates 2017-08-16 00:24:06 +01:00
typeobj.c Warning fixes for 64bit visual c++ on Windows 2015-07-03 20:59:24 +01:00
typesys.c Improve description of template_parameters_resolve 2017-08-16 00:24:24 +01:00
wrapfunc.c Remove cvs/svn Id strings 2013-01-12 01:21:16 +00:00