diff options
Diffstat (limited to 'extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppClassHeader.mtl')
-rw-r--r-- | extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppClassHeader.mtl | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppClassHeader.mtl b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppClassHeader.mtl index 227947b9fd0..d9b6372d9ed 100644 --- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppClassHeader.mtl +++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/src/org/eclipse/papyrus/cpp/codegen/acceleo/CppClassHeader.mtl @@ -11,10 +11,10 @@ [import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassAttributesDeclaration/] [import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassOperationsDeclaration/] [import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassOperationsImplementation/] +[import org::eclipse::papyrus::cpp::codegen::acceleo::util::operation::CppOperations/] [import org::eclipse::papyrus::cpp::codegen::acceleo::util::CppTemplates/] [import org::eclipse::papyrus::cpp::codegen::acceleo::util::CppDocumentation/] - [template public classUnionOrStruct(classifier : Classifier)] [if (hasStereotype(C_Cpp::Union))] 'union' @@ -33,14 +33,34 @@ TODO: should be disabled by default, since non-static members can be initialized directly in C++ 011/] [template public defaultInitializer(classifier : Classifier) post(trim())] -[let attributeList : Set(Property) = attribute->select( - (isStatic = false) and - (defaultValue <> null) and - (defaultValue.stringValue() <> null))] -[if not attributeList->isEmpty()] - [classifier.name/]() : [for (a : Property | attributeList) separator(', ') - ][name/]([defaultValue.stringValue()/])[/for] {} -[/if][/let] +[comment +Bug 422373: The default initializer should not be generated if there are any user-defined + constructors. In plain C++ code, the existence of a constructor with parameters + means that the compiler will not synthesize a default one. + + E.g., this would be invalid in plain C++ code: + class T1 { }; + class T2 { public: T(int); }; + T1 * t1 = new T1; // OK, sythesized default constructor used + T2 * t2a = new T2(5); // OK, user-defined constructor used + T2 * t2b = new T2; // ERROR, default constructor was not synthesized + + Also, if the user has provided a default constructor in the code, we don't need + to generate a second copy here. A default constructor should only be generated + here if the compiler would have synthesized one anyhow. Otherwise the default + property values should be set in the constructors that are generated by + CppClassOperationsDeclaration. +/] +[if getOwnedOperations()->any(hasStereotype(l2::Create)) = null] + [let attributeList : Set(Property) = attribute->select( + (isStatic = false) and + (defaultValue <> null) and + (defaultValue.stringValue() <> null))] + [if not attributeList->isEmpty()] + [classifier.name/]() : [for (a : Property | attributeList) separator(', ') + ][name/]([defaultValue.stringValue()/])[/for] {} + [/if][/let] +[/if] [/template] |