Skip to content

Commit f6f00fe

Browse files
committed
Do not add copy constructor if it was deleted or private
obviously copying the object is explicitly prohibited
1 parent 4c61ee7 commit f6f00fe

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

generator/abstractmetabuilder.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,8 +1109,15 @@ void AbstractMetaBuilder::traverseFunctions(ScopeModelItem scope_item, AbstractM
11091109
bool isInvalidDestructor = meta_function->isDestructor() && meta_function->isPrivate();
11101110
bool isInvalidConstructor = meta_function->isConstructor()
11111111
&& (meta_function->isPrivate() || meta_function->isInvalid());
1112+
if (isInvalidConstructor && meta_function->arguments().size() == 1 &&
1113+
meta_class->qualifiedCppName() == meta_function->arguments().at(0)->type()->typeEntry()->qualifiedCppName())
1114+
{
1115+
// deleted or private copy constructor, it seems copying is not allowed
1116+
meta_class->typeEntry()->setNoCopy(true);
1117+
}
11121118
if ((isInvalidDestructor || isInvalidConstructor)
1113-
&& !meta_class->hasNonPrivateConstructor()) {
1119+
&& !meta_class->hasNonPrivateConstructor())
1120+
{
11141121
*meta_class += AbstractMetaAttributes::Final;
11151122
} else if (meta_function->isConstructor() && !meta_function->isPrivate()) {
11161123
*meta_class -= AbstractMetaAttributes::Final;
@@ -1434,11 +1441,6 @@ AbstractMetaFunction *AbstractMetaBuilder::traverseFunction(FunctionModelItem fu
14341441
meta_function->setFunctionType(AbstractMetaFunction::SlotFunction);
14351442
}
14361443

1437-
if (function_item->isDeleted()) {
1438-
meta_function->setInvalid(true);
1439-
return meta_function;
1440-
}
1441-
14421444
ArgumentList arguments = function_item->arguments();
14431445
AbstractMetaArgumentList meta_arguments;
14441446

@@ -1494,7 +1496,7 @@ AbstractMetaFunction *AbstractMetaBuilder::traverseFunction(FunctionModelItem fu
14941496
}
14951497
}
14961498

1497-
// If we where not able to translate the default argument make it
1499+
// If we were not able to translate the default argument make it
14981500
// reset all default arguments before this one too.
14991501
for (int i=0; i<first_default_argument; ++i) {
15001502
meta_arguments[i]->setDefaultValueExpression(QString());
@@ -1506,6 +1508,11 @@ AbstractMetaFunction *AbstractMetaBuilder::traverseFunction(FunctionModelItem fu
15061508
}
15071509
}
15081510

1511+
if (function_item->isDeleted()) {
1512+
meta_function->setInvalid(true);
1513+
return meta_function;
1514+
}
1515+
15091516
return meta_function;
15101517
}
15111518

generator/shellheadergenerator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ void ShellHeaderGenerator::write(QTextStream& s, const AbstractMetaClass* meta_c
364364
}
365365

366366
if (meta_class->typeEntry()->isValue()
367-
&& !copyConstructorSeen && defaultConstructorSeen) {
367+
&& !copyConstructorSeen && defaultConstructorSeen && !meta_class->typeEntry()->hasNoCopy())
368+
{
368369
QString className = meta_class->generateShellClass() ? shellClassName(meta_class) : meta_class->qualifiedCppName();
369370
s << meta_class->qualifiedCppName() << "* new_" << meta_class->name() << "(const " << meta_class->qualifiedCppName() << "& other) {" << endl;
370371
s << className << "* a = new " << className << "();" << endl;

generator/typesystem.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ class ComplexTypeEntry : public TypeEntry
801801
m_generic_class(false),
802802
m_createShell(false),
803803
m_createPromoter(false),
804+
m_noCopy(false),
804805
m_type_flags(0)
805806
{
806807
Include inc;
@@ -931,6 +932,9 @@ class ComplexTypeEntry : public TypeEntry
931932
bool isGenericClass() const { return m_generic_class; }
932933
void setGenericClass(bool isGeneric) { m_generic_class = isGeneric; }
933934

935+
bool hasNoCopy() const { return m_noCopy; }
936+
void setNoCopy(bool noCopy) { m_noCopy = noCopy; }
937+
934938
private:
935939
IncludeList m_extra_includes;
936940
Include m_include;
@@ -948,6 +952,7 @@ class ComplexTypeEntry : public TypeEntry
948952
uint m_generic_class : 1;
949953
uint m_createShell : 1;
950954
uint m_createPromoter : 1;
955+
uint m_noCopy : 1;
951956

952957
QString m_polymorphic_id_value;
953958
QString m_lookup_name;

0 commit comments

Comments
 (0)