diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html index 858ce8c9e..0192b171a 100644 --- a/Doc/Manual/SWIGPlus.html +++ b/Doc/Manual/SWIGPlus.html @@ -334,11 +334,11 @@ disable the implicit constructor/desctructor generation manually.
-To do so, the %nodefaultctor, %nodefaultdtor and -%nocopyctordirectives can be used. Note that these directives -only affects the implicit generation, and they have no effect if -the default/copy constructors or destructor are explicitly declared in -the class interface. +To do so, the %nodefaultctor and %nodefaultdtor +directives can be used. Note that these directives only affects the +implicit generation, and they have no effect if the default/copy +constructors or destructor are explicitly declared in the class +interface.
@@ -371,7 +371,7 @@ class Bar { public: Bar(); // The default constructor is generated, since is declared }; -%defaultctor; // Enable the creation of default constructors again +%clearnodefaultctor; // Enable the creation of default constructors again @@ -392,30 +392,6 @@ class Foo { // No destructor is generated, unless is declared -
-The %nocopyctor disable the automatic generation of the copy -constructor, but also has no effect over classes that explicitly -declare a public copy constructor: -
- -
-%nocopytor Foo; // Disable the copy constructor for class Foo.
-class Foo {
-public:
- Foo();
-};
-%nocopytor Bar; // Has no effect on Bar
-class Bar {
-public:
- Bar(const Bar& b); // Copy constructor is generated
-};
-
--
-Compatibility Note: The generation of default constructors/implicit destructors was made the default behavior in SWIG diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 5473ca4ce..15c2e2c50 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -90,7 +90,6 @@ CPP_TEST_CASES += \ const_const_2 \ constant_pointers \ constover \ - constructor_copy \ constructor_exception \ constructor_explicit \ constructor_value \ diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index 2b816293f..450654823 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -570,7 +570,8 @@ public: /* If class is abstract. No default constructor. Sorry */ if (Getattr(n,"abstract")) { Delattr(n,"allocate:default_constructor"); - } else if (!Getattr(n,"allocate:default_constructor")) { + } + if (!Getattr(n,"allocate:default_constructor")) { /* Check base classes */ List *bases = Getattr(n,"allbases"); int allows_default = 1; @@ -588,7 +589,10 @@ public: } } if (!Getattr(n,"allocate:has_copy_constructor")) { - if (!Getattr(n,"allocate:copy_constructor") && !Getattr(n,"abstract")) { + if (Getattr(n,"abstract")) { + Delattr(n,"allocate:copy_constructor"); + } + if (!Getattr(n,"allocate:copy_constructor")) { /* Check base classes */ List *bases = Getattr(n,"allbases"); int allows_copy = 1; diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index ea7f0f9d3..5dd5f07a9 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -352,7 +352,7 @@ void swig_pragma(char *lang, char *name, char *value) { GenerateDefault = 1; } else if ((strcmp(name,"no_default") == 0) || ((strcmp(name,"nodefault") == 0))) { Swig_warning(WARN_DEPRECATED_NODEFAULT, "SWIG",1, - "dangerous, use %nodefaultctor, %nodefaultdtor or %nocopyctor instead.\n"); + "dangerous, use %nodefaultctor, %nodefaultdtor instead.\n"); GenerateDefault = 0; } else if (strcmp(name,"attributefunction") == 0) { String *nvalue = NewString(value); @@ -2050,7 +2050,7 @@ static Node *makeCopyConstructor(Node *n) Swig_symbol_setscope(oldscope); return cn; } - +/* static Node *makeConstructor(Node *n) { Node *cn = NewHash(); @@ -2067,6 +2067,30 @@ static Node *makeConstructor(Node *n) Swig_symbol_setscope(oldscope); return cn; } +*/ + +static Node *makeConstructor(Node *n) +{ + Node *cn = Copy(n); + String *name = Getattr(n,"name"); + String *rname = 0; + String *dname = NewStringf("%s::",name); + + if (SwigType_istemplate(name)) { + rname = SwigType_templateprefix(name); + name = rname; + } + String *lname = Swig_scopename_last(name); + Append(dname,lname); + SetFlag(cn,"feature:new"); + Setattr(cn,"decl","f()."); + Swig_features_get(Swig_cparse_features(), 0, dname, Getattr(cn,"decl"), cn); + Delete(rname); + Delete(dname); + Delete(lname); + + return cn; +} static Node *makeDestructor(Node *n) { @@ -2095,28 +2119,6 @@ int Language::classHandler(Node *n) { bool hasDirector = Swig_directorclass(n) ? true : false; - int odefault = (GenerateDefault && !GetFlag(n,"feature:nodefault")); - if (!ImportMode && (!GetFlag(n,"feature:nocopyctor")) && odefault) { - if (!Getattr(n,"has_copy_constructor") && !Getattr(n,"allocate:has_copy_constructor") - && (Getattr(n,"allocate:copy_constructor"))) { - if (!Abstract) { - Node *cn = makeCopyConstructor(CurrentClass); - appendChild(n,cn); - } - } - } - cplus_mode = PUBLIC; - if (!ImportMode && !GetFlag(n,"feature:nodefaultctor") && odefault) { - if (!Getattr(n,"has_constructor") && !Getattr(n,"allocate:has_constructor") - && (Getattr(n,"allocate:default_constructor"))) { - /* Note: will need to change this to support different kinds of classes */ - if (!Abstract) { - Node *cn = makeConstructor(CurrentClass); - appendChild(n,cn); - } - } - } - /* Emit all of the class members */ emit_children(n); @@ -2132,6 +2134,18 @@ int Language::classHandler(Node *n) { SmartPointer = 0; } + cplus_mode = PUBLIC; + int odefault = (GenerateDefault && !GetFlag(n,"feature:nodefault")); + if (!ImportMode && (GenerateDefault && !GetFlag(n,"feature:nodefault"))) { + if (!Getattr(n,"has_constructor") && !Getattr(n,"allocate:has_constructor") && (Getattr(n,"allocate:default_constructor"))) { + /* Note: will need to change this to support different kinds of classes */ + if (!Abstract) { + Node *cn = makeConstructor(CurrentClass); + constructorHandler(cn); + Delete(cn); + } + } + } if (!ImportMode && !GetFlag(n,"feature:nodefaultdtor") && odefault) { if (!Getattr(n,"has_destructor") && (!Getattr(n,"allocate:has_destructor")) && (Getattr(n,"allocate:default_destructor"))) { diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx index ef4c32c32..2f9bb8e33 100644 --- a/Source/Modules/main.cxx +++ b/Source/Modules/main.cxx @@ -85,8 +85,7 @@ static const char *usage2 = (const char*)"\ -nocontract - Turn off contract checking \n\ -nodefault - Do not generate constructors, destructor or copy constructors (dangerous, don't use it)\n\ -nodefaultctor - Do not generate implicit default constructors\n\ - -nodefaultdctor - Do not generate implicit default destructors (dangerous, use %nodefaultdtor instead)\n\ - -nocopyctor - Do not generate implicit copy constructors\n\ + -nodefaultdtor - Do not generate implicit default destructors (dangerous, use %nodefaultdtor instead)\n\ -nodirprot - Do not wrap director protected members\n\ -noexcept - Do not wrap exception specifiers\n\ -addextern - Add extra extern declarations\n\ @@ -448,7 +447,7 @@ void SWIG_getoptions(int argc, char *argv[]) } else if ((strcmp(argv[i],"-no_default") == 0) || (strcmp(argv[i],"-nodefault") == 0)) { GenerateDefault = 0; Swig_warning(WARN_DEPRECATED_NODEFAULT, "SWIG",1, - "dangerous, use -nodefaultctor, -nodefaultdtor or -nocopyctor instead.\n"); + "dangerous, use -nodefaultctor, -nodefaultdtor instead.\n"); Swig_mark_arg(i); } else if ((strcmp(argv[i],"-nodefaultctor") == 0)) { SWIG_setfeature("feature:nodefaultctor","1"); @@ -456,9 +455,11 @@ void SWIG_getoptions(int argc, char *argv[]) } else if ((strcmp(argv[i],"-nodefaultdtor") == 0)) { SWIG_setfeature("feature:nodefaultdtor","1"); Swig_mark_arg(i); +#if 0 } else if ((strcmp(argv[i],"-nocopyctor") == 0)) { SWIG_setfeature("feature:nocopyctor","1"); Swig_mark_arg(i); +#endif } else if (strcmp(argv[i],"-noexcept") == 0) { NoExcept = 1; Swig_mark_arg(i);