aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-12 13:50:24 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-13 13:02:26 +0200
commit85451c40f23a7298b5f35744e8588307e124a751 (patch)
treed507d772fa63c084d64ac1886caa91e23c4864f2
parent6e2eb6917620675b8bbcce53a31204a1ecfb2424 (diff)
shiboken2: Use an AbstractMetaType for "void"
Previously, nullptr for an AbstractMetaType meant "void", particularly for function return types. The problem with this is that it causes unexpected crashes when dealing with template types like QFuture<void> due to one of the instantiations of the AbstractMetaType being nullptr. Use an AbstractMetaType based on the existing "void" type entry for this. Task-number: PYSIDE-1202 Change-Id: Ib06035cc7903480fd509f7e927d9114c55d51b62 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r--sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp60
-rw-r--r--sources/shiboken2/ApiExtractor/abstractmetalang.cpp30
-rw-r--r--sources/shiboken2/ApiExtractor/abstractmetalang.h8
-rw-r--r--sources/shiboken2/ApiExtractor/tests/testaddfunction.cpp4
-rw-r--r--sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp2
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.cpp31
-rw-r--r--sources/shiboken2/generator/shiboken2/headergenerator.cpp9
-rw-r--r--sources/shiboken2/generator/shiboken2/overloaddata.cpp22
-rw-r--r--sources/shiboken2/generator/shiboken2/shibokengenerator.cpp2
9 files changed, 89 insertions, 79 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
index 6b72d6b71..b06376866 100644
--- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
+++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
@@ -1300,7 +1300,7 @@ void AbstractMetaBuilderPrivate::traverseFunctions(ScopeModelItem scopeItem,
QPropertySpec *read = nullptr;
if (!metaFunction->isSignal() && (read = metaClass->propertySpecForRead(metaFunction->name()))) {
// Property reader must be in the form "<type> name()"
- if (metaFunction->type() && (read->typeEntry() == metaFunction->type()->typeEntry())
+ if (read->typeEntry() == metaFunction->type()->typeEntry()
&& metaFunction->arguments().isEmpty()) {
*metaFunction += AbstractMetaAttributes::PropertyReader;
metaFunction->setPropertySpec(read);
@@ -1309,14 +1309,14 @@ void AbstractMetaBuilderPrivate::traverseFunctions(ScopeModelItem scopeItem,
// Property setter must be in the form "void name(<type>)"
// Make sure the function was created with all arguments; some argument can be
// missing during the parsing because of errors in the typesystem.
- if ((!metaFunction->type()) && (metaFunction->arguments().size() == 1)
+ if (metaFunction->isVoid() && metaFunction->arguments().size() == 1
&& (write->typeEntry() == metaFunction->arguments().at(0)->type()->typeEntry())) {
*metaFunction += AbstractMetaAttributes::PropertyWriter;
metaFunction->setPropertySpec(write);
}
} else if (QPropertySpec *reset = metaClass->propertySpecForReset(metaFunction->name())) {
// Property resetter must be in the form "void name()"
- if ((!metaFunction->type()) && metaFunction->arguments().isEmpty()) {
+ if (metaFunction->isVoid() && metaFunction->arguments().isEmpty()) {
*metaFunction += AbstractMetaAttributes::PropertyResetter;
metaFunction->setPropertySpec(reset);
}
@@ -1520,16 +1520,13 @@ AbstractMetaFunction* AbstractMetaBuilderPrivate::traverseFunction(const AddedFu
{
QString errorMessage;
- AbstractMetaType *returnType = nullptr;
- if (addedFunc->returnType().name != QLatin1String("void")) {
- returnType = translateType(addedFunc->returnType(), &errorMessage);
- if (!returnType) {
- qCWarning(lcShiboken, "%s",
- qPrintable(msgAddedFunctionInvalidReturnType(addedFunc->name(),
- addedFunc->returnType().name,
- errorMessage)));
- return nullptr;
- }
+ AbstractMetaType *returnType = translateType(addedFunc->returnType(), &errorMessage);
+ if (!returnType) {
+ qCWarning(lcShiboken, "%s",
+ qPrintable(msgAddedFunctionInvalidReturnType(addedFunc->name(),
+ addedFunc->returnType().name,
+ errorMessage)));
+ return nullptr;
}
auto metaFunction = new AbstractMetaFunction(addedFunc);
@@ -1810,10 +1807,12 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio
QString errorMessage;
switch (metaFunction->functionType()) {
case AbstractMetaFunction::DestructorFunction:
+ metaFunction->setType(AbstractMetaType::createVoid());
break;
case AbstractMetaFunction::ConstructorFunction:
metaFunction->setExplicit(functionItem->isExplicit());
metaFunction->setName(currentClass->name());
+ metaFunction->setType(AbstractMetaType::createVoid());
break;
default: {
TypeInfo returnType = functionItem->type();
@@ -1824,17 +1823,14 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio
return nullptr;
}
- AbstractMetaType *type = nullptr;
- if (!returnType.isVoid()) {
- type = translateType(returnType, currentClass, {}, &errorMessage);
- if (!type) {
- const QString reason = msgUnmatchedReturnType(functionItem, errorMessage);
- qCWarning(lcShiboken, "%s",
- qPrintable(msgSkippingFunction(functionItem, originalQualifiedSignatureWithReturn, reason)));
- m_rejectedFunctions.insert(originalQualifiedSignatureWithReturn, AbstractMetaBuilder::UnmatchedReturnType);
- delete metaFunction;
- return nullptr;
- }
+ AbstractMetaType *type = translateType(returnType, currentClass, {}, &errorMessage);
+ if (!type) {
+ const QString reason = msgUnmatchedReturnType(functionItem, errorMessage);
+ qCWarning(lcShiboken, "%s",
+ qPrintable(msgSkippingFunction(functionItem, originalQualifiedSignatureWithReturn, reason)));
+ m_rejectedFunctions.insert(originalQualifiedSignatureWithReturn, AbstractMetaBuilder::UnmatchedReturnType);
+ delete metaFunction;
+ return nullptr;
}
metaFunction->setType(type);
@@ -1972,7 +1968,7 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const AddedFunction:
QString typeName = typeInfo.name;
if (typeName == QLatin1String("void"))
- return nullptr;
+ return AbstractMetaType::createVoid();
type = typeDb->findType(typeName);
if (!type)
@@ -2022,12 +2018,9 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const AddedFunction:
metaType->setConstant(typeInfo.isConstant);
if (isTemplate) {
for (const QString& templateArg : qAsConst(templateArgs)) {
- AbstractMetaType *metaArgType = nullptr;
- if (templateArg != QLatin1String("void")) {
- metaArgType = translateType(AddedFunction::TypeInfo::fromSignature(templateArg), errorMessage);
- if (!metaArgType)
- return nullptr;
- }
+ AbstractMetaType *metaArgType = translateType(AddedFunction::TypeInfo::fromSignature(templateArg), errorMessage);
+ if (!metaArgType)
+ return nullptr;
metaType->addInstantiation(metaArgType);
}
metaType->setTypeUsagePattern(AbstractMetaType::ContainerPattern);
@@ -2113,6 +2106,9 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo
TranslateTypeFlags flags,
QString *errorMessageIn)
{
+ if (_typei.isVoid())
+ return AbstractMetaType::createVoid();
+
// 1. Test the type info without resolving typedefs in case this is present in the
// type system
const bool resolveType = !flags.testFlag(AbstractMetaBuilder::DontResolveType);
@@ -2685,7 +2681,7 @@ bool AbstractMetaBuilderPrivate::inheritTemplate(AbstractMetaClass *subclass,
QScopedPointer<AbstractMetaFunction> f(function->copy());
f->setArguments(AbstractMetaArgumentList());
- if (function->type()) { // Non-void
+ if (!function->isVoid()) {
AbstractMetaType *returnType = inheritTemplateType(templateTypes, function->type());
if (!returnType)
continue;
diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp
index 80ec20b46..9c54cc0d4 100644
--- a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp
+++ b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp
@@ -319,8 +319,11 @@ AbstractMetaType::TypeUsagePattern AbstractMetaType::determineUsagePattern() con
if (m_typeEntry->isPrimitive() && (actualIndirections() == 0 || passByConstRef()))
return PrimitivePattern;
- if (m_typeEntry->isVoid())
- return NativePointerPattern;
+ if (m_typeEntry->isVoid()) {
+ return m_arrayElementCount < 0 && m_referenceType == NoReference
+ && m_indirections.isEmpty() && m_constant == 0 && m_volatile == 0
+ ? VoidPattern : NativePointerPattern;
+ }
if (m_typeEntry->isVarargs())
return VarargsPattern;
@@ -410,6 +413,16 @@ bool AbstractMetaType::compare(const AbstractMetaType &rhs, ComparisonFlags flag
return true;
}
+AbstractMetaType *AbstractMetaType::createVoid()
+{
+ static const TypeEntry *voidTypeEntry = TypeDatabase::instance()->findType(QLatin1String("void"));
+ Q_ASSERT(voidTypeEntry);
+ auto *metaType = new AbstractMetaType;
+ metaType->setTypeEntry(voidTypeEntry);
+ metaType->decideUsagePattern();
+ return metaType;
+}
+
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug d, const AbstractMetaType *at)
{
@@ -642,8 +655,7 @@ AbstractMetaFunction *AbstractMetaFunction::copy() const
cpy->setImplementingClass(implementingClass());
cpy->setFunctionType(functionType());
cpy->setDeclaringClass(declaringClass());
- if (type())
- cpy->setType(type()->copy());
+ cpy->setType(type()->copy());
cpy->setConstant(isConstant());
cpy->setExceptionSpecification(m_exceptionSpecification);
cpy->setAllowThreadModification(m_allowThreadModification);
@@ -653,8 +665,7 @@ AbstractMetaFunction *AbstractMetaFunction::copy() const
for (AbstractMetaArgument *arg : m_arguments)
cpy->addArgument(arg->copy());
- Q_ASSERT((!type() && !cpy->type())
- || (type()->instantiations() == cpy->type()->instantiations()));
+ Q_ASSERT(type()->instantiations() == cpy->type()->instantiations());
return cpy;
}
@@ -663,7 +674,7 @@ bool AbstractMetaFunction::usesRValueReferences() const
{
if (m_functionType == MoveConstructorFunction || m_functionType == MoveAssignmentOperatorFunction)
return true;
- if (m_type && m_type->referenceType() == RValueReference)
+ if (m_type->referenceType() == RValueReference)
return true;
for (const AbstractMetaArgument *a : m_arguments) {
if (a->type()->referenceType() == RValueReference)
@@ -828,8 +839,7 @@ bool AbstractMetaFunction::isDeprecated() const
bool AbstractMetaFunction::autoDetectAllowThread() const
{
// Disallow for simple getter functions.
- const bool maybeGetter = m_constant != 0 && m_type != nullptr
- && m_arguments.isEmpty();
+ const bool maybeGetter = m_constant != 0 && !isVoid() && m_arguments.isEmpty();
return !maybeGetter;
}
@@ -1929,6 +1939,7 @@ bool AbstractMetaClass::hasPrivateCopyConstructor() const
void AbstractMetaClass::addDefaultConstructor()
{
auto *f = new AbstractMetaFunction;
+ f->setType(AbstractMetaType::createVoid());
f->setOriginalName(name());
f->setName(name());
f->setOwnerClass(this);
@@ -1947,6 +1958,7 @@ void AbstractMetaClass::addDefaultConstructor()
void AbstractMetaClass::addDefaultCopyConstructor(bool isPrivate)
{
auto f = new AbstractMetaFunction;
+ f->setType(AbstractMetaType::createVoid());
f->setOriginalName(name());
f->setName(name());
f->setOwnerClass(this);
diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.h b/sources/shiboken2/ApiExtractor/abstractmetalang.h
index dcc3e58d6..5d075f1e8 100644
--- a/sources/shiboken2/ApiExtractor/abstractmetalang.h
+++ b/sources/shiboken2/ApiExtractor/abstractmetalang.h
@@ -293,7 +293,8 @@ public:
ContainerPattern,
SmartPointerPattern,
VarargsPattern,
- ArrayPattern
+ ArrayPattern,
+ VoidPattern // Plain "void", no "void *" or similar.
};
Q_ENUM(TypeUsagePattern)
@@ -416,6 +417,8 @@ public:
return m_pattern == FlagsPattern;
}
+ bool isVoid() const { return m_pattern == VoidPattern; }
+
bool isConstant() const
{
return m_constant;
@@ -530,6 +533,8 @@ public:
bool compare(const AbstractMetaType &rhs, ComparisonFlags = {}) const;
+ static AbstractMetaType *createVoid();
+
private:
TypeUsagePattern determineUsagePattern() const;
QString formatSignature(bool minimal) const;
@@ -881,6 +886,7 @@ public:
bool isModifiedRemoved(int types = TypeSystem::All) const;
+ bool isVoid() const { return m_type->isVoid(); }
AbstractMetaType *type() const
{
return m_type;
diff --git a/sources/shiboken2/ApiExtractor/tests/testaddfunction.cpp b/sources/shiboken2/ApiExtractor/tests/testaddfunction.cpp
index ca4af9a10..a131e7fe2 100644
--- a/sources/shiboken2/ApiExtractor/tests/testaddfunction.cpp
+++ b/sources/shiboken2/ApiExtractor/tests/testaddfunction.cpp
@@ -145,7 +145,7 @@ void TestAddFunction::testAddFunctionConstructor()
QCOMPARE(addedFunc->functionType(), AbstractMetaFunction::ConstructorFunction);
QCOMPARE(addedFunc->arguments().size(), 1);
QVERIFY(addedFunc->isUserAdded());
- QVERIFY(!addedFunc->type());
+ QVERIFY(addedFunc->isVoid());
}
void TestAddFunction::testAddFunctionTagDefaultValues()
@@ -167,7 +167,7 @@ void TestAddFunction::testAddFunctionTagDefaultValues()
QCOMPARE(addedFunc->visibility(), AbstractMetaFunction::Public);
QCOMPARE(addedFunc->functionType(), AbstractMetaFunction::NormalFunction);
QVERIFY(addedFunc->isUserAdded());
- QVERIFY(!addedFunc->type());
+ QVERIFY(addedFunc->isVoid());
}
void TestAddFunction::testAddFunctionCodeSnippets()
diff --git a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp
index 826e8056c..5e75cbf87 100644
--- a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp
+++ b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp
@@ -2081,7 +2081,7 @@ void QtDocGenerator::writeFunctionParametersType(QTextStream &s, const AbstractM
writeParameterType(s, cppClass, arg);
}
- if (!func->isConstructor() && func->type()) {
+ if (!func->isConstructor() && !func->isVoid()) {
QString retType;
// check if the return type was modified
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
index c1f1b21db..ea970331e 100644
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
@@ -247,7 +247,7 @@ const AbstractMetaFunction *CppGenerator::boolCast(const AbstractMetaClass *meta
return nullptr;
// TODO: This could be configurable someday
const AbstractMetaFunction *func = metaClass->findFunction(QLatin1String("isNull"));
- if (!func || !func->type() || !func->type()->typeEntry()->isPrimitive() || !func->isPublic())
+ if (!func || func->isVoid() || !func->type()->typeEntry()->isPrimitive() || !func->isPublic())
return nullptr;
auto pte = static_cast<const PrimitiveTypeEntry *>(func->type()->typeEntry());
while (pte->referencedTypeEntry())
@@ -892,9 +892,9 @@ QString CppGenerator::virtualMethodReturn(QTextStream &s,
const AbstractMetaFunction *func,
const FunctionModificationList &functionModifications)
{
- const AbstractMetaType *returnType = func->type();
- if (!returnType)
+ if (func->isVoid())
return QLatin1String("return;");
+ const AbstractMetaType *returnType = func->type();
for (const FunctionModification &mod : functionModifications) {
for (const ArgumentModification &argMod : mod.argument_mods) {
if (argMod.index == 0 && !argMod.replacedDefaultExpression.isEmpty()) {
@@ -951,7 +951,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s,
((func->name() == QLatin1String("metaObject")) || (func->name() == QLatin1String("qt_metacall"))))
return;
- const TypeEntry *retType = func->type() ? func->type()->typeEntry() : nullptr;
+ const TypeEntry *retType = func->type()->typeEntry();
const QString funcName = func->isOperatorOverload() ? pythonOperatorFunctionName(func) : func->name();
QString prefix = wrapperName(func->ownerClass()) + QLatin1String("::");
@@ -994,7 +994,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s,
<< R"(] << '\n';)" << '\n';
}
// PYSIDE-803: Build a boolean cache for unused overrides.
- const bool multi_line = retType == nullptr || !snips.isEmpty() || func->isAbstract();
+ const bool multi_line = func->isVoid() || !snips.isEmpty() || func->isAbstract();
s << INDENT << "if (m_PyMethodCache[" << cacheIndex << "])" << (multi_line ? " {\n" : "\n");
{
Indentation indentation(INDENT);
@@ -1126,7 +1126,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s,
}
s << INDENT << "}\n";
- if (retType) {
+ if (!func->isVoid()) {
if (invalidateReturn)
s << INDENT << "bool invalidateArg0 = " << PYTHON_RETURN_VAR << "->ob_refcnt == 1;\n";
@@ -1211,7 +1211,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s,
writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionEnd, TypeSystem::NativeCode, func, lastArg);
}
- if (retType) {
+ if (!func->isVoid()) {
s << INDENT << "return ";
if (avoidProtectedHack() && retType->isEnum()) {
const AbstractMetaEnum *metaEnum = findAbstractMetaEnum(retType);
@@ -2329,6 +2329,7 @@ void CppGenerator::writeTypeCheck(QTextStream &s, const AbstractMetaType *argTyp
static void checkTypeViability(const AbstractMetaFunction *func, const AbstractMetaType *type, int argIdx)
{
if (!type
+ || type->isVoid()
|| !type->typeEntry()->isPrimitive()
|| type->indirections() == 0
|| (type->indirections() == 1 && type->typeUsagePattern() == AbstractMetaType::NativePointerAsArrayPattern)
@@ -2596,7 +2597,7 @@ void CppGenerator::writeConversionRule(QTextStream &s, const AbstractMetaFunctio
void CppGenerator::writeNoneReturn(QTextStream &s, const AbstractMetaFunction *func, bool thereIsReturnValue)
{
- if (thereIsReturnValue && (!func->type() || func->argumentRemoved(0)) && !injectedCodeHasReturnValueAttribution(func)) {
+ if (thereIsReturnValue && (func->isVoid() || func->argumentRemoved(0)) && !injectedCodeHasReturnValueAttribution(func)) {
s << INDENT << PYTHON_RETURN_VAR << " = Py_None;\n";
s << INDENT << "Py_INCREF(Py_None);\n";
}
@@ -3237,7 +3238,7 @@ QString CppGenerator::argumentNameFromIndex(const AbstractMetaFunction *func, in
} else if (argIndex == 0) {
AbstractMetaType *funcType = func->type();
AbstractMetaType *returnType = getTypeWithoutContainer(funcType);
- if (returnType) {
+ if (!returnType->isVoid()) {
pyArgName = QLatin1String(PYTHON_RETURN_VAR);
*wrappedClass = AbstractMetaClass::findClass(classes(), returnType->typeEntry());
} else {
@@ -3560,7 +3561,7 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f
if (isCtor) {
s << (useVAddr.isEmpty() ?
QString::fromLatin1("cptr = %1;").arg(methodCall) : useVAddr) << Qt::endl;
- } else if (func->type() && !func->isInplaceOperator()) {
+ } else if (!func->isVoid() && !func->isInplaceOperator()) {
bool writeReturnType = true;
if (avoidProtectedHack()) {
const AbstractMetaEnum *metaEnum = findAbstractMetaEnum(func->type());
@@ -3598,7 +3599,7 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f
// Convert result
if (!func->conversionRule(TypeSystem::TargetLangCode, 0).isEmpty()) {
writeConversionRule(s, func, TypeSystem::TargetLangCode, QLatin1String(PYTHON_RETURN_VAR));
- } else if (!isCtor && !func->isInplaceOperator() && func->type()
+ } else if (!isCtor && !func->isInplaceOperator() && !func->isVoid()
&& !injectedCodeHasReturnValueAttribution(func, TypeSystem::TargetLangCode)) {
s << INDENT << PYTHON_RETURN_VAR << " = ";
if (isObjectTypeUsedAsValueType(func->type())) {
@@ -4696,7 +4697,7 @@ void CppGenerator::writeRichCompareFunction(QTextStream &s, const GeneratorConte
}
if (generateOperatorCode) {
s << INDENT;
- if (func->type())
+ if (!func->isVoid())
s << func->type()->cppSignature() << " " << CPP_RETURN_VAR << " = ";
// expression
if (func->isPointerOperator())
@@ -4706,7 +4707,7 @@ void CppGenerator::writeRichCompareFunction(QTextStream &s, const GeneratorConte
s << '*';
s << CPP_ARG0 << ");\n";
s << INDENT << PYTHON_RETURN_VAR << " = ";
- if (func->type())
+ if (!func->isVoid())
writeToPythonConversion(s, func->type(), metaClass, QLatin1String(CPP_RETURN_VAR));
else
s << "Py_None;\n" << INDENT << "Py_INCREF(Py_None)";
@@ -4830,7 +4831,7 @@ void CppGenerator::writeSignatureInfo(QTextStream &s, const AbstractMetaFunction
if (multiple)
s << idx-- << ':';
s << funcName << '(' << args.join(QLatin1Char(',')) << ')';
- if (f->type())
+ if (!f->isVoid())
s << "->" << f->type()->pythonSignature();
s << Qt::endl;
}
@@ -6214,7 +6215,7 @@ void CppGenerator::writeReturnValueHeuristics(QTextStream &s, const AbstractMeta
AbstractMetaType *type = func->type();
if (!useReturnValueHeuristic()
|| !func->ownerClass()
- || !type
+ || type->isVoid()
|| func->isStatic()
|| func->isConstructor()
|| !func->typeReplaced(0).isEmpty()) {
diff --git a/sources/shiboken2/generator/shiboken2/headergenerator.cpp b/sources/shiboken2/generator/shiboken2/headergenerator.cpp
index 36ccefb58..107e28a4a 100644
--- a/sources/shiboken2/generator/shiboken2/headergenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/headergenerator.cpp
@@ -239,7 +239,8 @@ void HeaderGenerator::writeFunction(QTextStream &s, const AbstractMetaFunction *
s << INDENT << "inline " << (func->isStatic() ? "static " : "");
s << functionSignature(func, QString(), QLatin1String("_protected"), Generator::EnumAsInts|Generator::OriginalTypeDescription)
<< " { ";
- s << (func->type() ? "return " : "");
+ if (!func->isVoid())
+ s << "return ";
if (!func->isAbstract())
s << func->ownerClass()->qualifiedCppName() << "::";
s << func->originalName() << '(';
@@ -637,8 +638,10 @@ void HeaderGenerator::writeInheritedOverloads(QTextStream &s)
{
for (const AbstractMetaFunction *func : qAsConst(m_inheritedOverloads)) {
s << INDENT << "inline ";
- s << functionSignature(func, QString(), QString(), Generator::EnumAsInts|Generator::OriginalTypeDescription) << " { ";
- s << (func->type() ? "return " : "");
+ s << functionSignature(func, QString(), QString(), Generator::EnumAsInts|Generator::OriginalTypeDescription)
+ << " { ";
+ if (!func->isVoid())
+ s << "return ";
s << func->ownerClass()->qualifiedCppName() << "::" << func->originalName() << '(';
QStringList args;
const AbstractMetaArgumentList &arguments = func->arguments();
diff --git a/sources/shiboken2/generator/shiboken2/overloaddata.cpp b/sources/shiboken2/generator/shiboken2/overloaddata.cpp
index 36725d3fc..9f79060da 100644
--- a/sources/shiboken2/generator/shiboken2/overloaddata.cpp
+++ b/sources/shiboken2/generator/shiboken2/overloaddata.cpp
@@ -579,10 +579,8 @@ QStringList OverloadData::returnTypes() const
for (const AbstractMetaFunction *func : m_overloads) {
if (!func->typeReplaced(0).isEmpty())
retTypes << func->typeReplaced(0);
- else if (func->type() && !func->argumentRemoved(0))
+ else if (!func->argumentRemoved(0))
retTypes << func->type()->cppSignature();
- else
- retTypes << QLatin1String("void");
}
return retTypes.values();
}
@@ -878,12 +876,9 @@ QString OverloadData::dumpGraph() const
// Shows all function signatures
s << "legend [fontsize=9 fontname=freemono shape=rect label=\"";
for (const AbstractMetaFunction *func : m_overloads) {
- s << "f" << functionNumber(func) << " : ";
- if (func->type())
- s << toHtml(func->type()->cppSignature());
- else
- s << "void";
- s << ' ' << toHtml(func->minimalSignature()) << "\\l";
+ s << "f" << functionNumber(func) << " : "
+ << toHtml(func->type()->cppSignature())
+ << ' ' << toHtml(func->minimalSignature()) << "\\l";
}
s << "\"];\n";
@@ -903,12 +898,9 @@ QString OverloadData::dumpGraph() const
s << "</td></tr>";
// Function return type
- s << "<tr><td bgcolor=\"gray\" align=\"right\">original type</td><td bgcolor=\"gray\" align=\"left\">";
- if (rfunc->type())
- s << toHtml(rfunc->type()->cppSignature());
- else
- s << "void";
- s << "</td></tr>";
+ s << "<tr><td bgcolor=\"gray\" align=\"right\">original type</td><td bgcolor=\"gray\" align=\"left\">"
+ << toHtml(rfunc->type()->cppSignature())
+ << "</td></tr>";
// Shows type changes for all function signatures
for (const AbstractMetaFunction *func : m_overloads) {
diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
index 8cea5aeda..3cd6b8e53 100644
--- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
@@ -1862,7 +1862,7 @@ void ShibokenGenerator::writeCodeSnips(QTextStream &s,
if (func->isConstructor()) {
code.replace(QLatin1String("%0."), QLatin1String("cptr->"));
code.replace(QLatin1String("%0"), QLatin1String("cptr"));
- } else if (func->type()) {
+ } else if (!func->isVoid()) {
QString returnValueOp = isPointerToWrapperType(func->type())
? QLatin1String("%1->") : QLatin1String("%1.");
if (ShibokenGenerator::isWrapperType(func->type()))