summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-04-08 15:06:58 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-09 19:10:16 -0300
commit38e7c4839a89fa2bf7602143d779eb99dee5c9de (patch)
treeebf3bb05435530e939cd66013d1305e58e5aa336
parent190b04bd9d47ed5e4b6d9d401b8574b36da105e5 (diff)
Fixed conversion operators type resolution for references to types.
This is fixes bug #716: http://bugs.pyside.org/show_bug.cgi?id=716 Unit tests were added as usual. Reviewed by Hugo Parente <hugo.lima@openbossa.org> Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r--abstractmetabuilder.cpp5
-rw-r--r--tests/testconversionoperator.cpp58
-rw-r--r--tests/testconversionoperator.h2
3 files changed, 65 insertions, 0 deletions
diff --git a/abstractmetabuilder.cpp b/abstractmetabuilder.cpp
index 72f7ab91..45ceab87 100644
--- a/abstractmetabuilder.cpp
+++ b/abstractmetabuilder.cpp
@@ -1334,6 +1334,11 @@ void AbstractMetaBuilder::fixReturnTypeOfConversionOperator(AbstractMetaFunction
TypeDatabase* types = TypeDatabase::instance();
QString castTo = metaFunction->name().remove(QRegExp("^operator ")).trimmed();
+ if (castTo.endsWith('&'))
+ castTo.chop(1);
+ if (castTo.startsWith("const "))
+ castTo.remove(0, 6);
+
TypeEntry* retType = types->findType(castTo);
if (!retType)
return;
diff --git a/tests/testconversionoperator.cpp b/tests/testconversionoperator.cpp
index b6d1ccf5..e14388e3 100644
--- a/tests/testconversionoperator.cpp
+++ b/tests/testconversionoperator.cpp
@@ -116,6 +116,64 @@ void TestConversionOperator::testRemovedConversionOperator()
QCOMPARE(classA->implicitConversions().count(), 0);
}
+void TestConversionOperator::testConversionOperatorReturningReference()
+{
+ const char cppCode[] = "\
+ struct A {};\
+ struct B {\
+ operator A&() const;\
+ };";
+ const char xmlCode[] = "\
+ <typesystem package='Foo'>\
+ <value-type name='A' />\
+ <value-type name='B' />\
+ </typesystem>";
+
+ TestUtil t(cppCode, xmlCode);
+ AbstractMetaClassList classes = t.builder()->classes();
+ AbstractMetaClass* classA = classes.findClass("A");
+ AbstractMetaClass* classB = classes.findClass("B");
+ QVERIFY(classA);
+ QVERIFY(classB);
+ QCOMPARE(classA->functions().count(), 2);
+ QCOMPARE(classB->functions().count(), 3);
+ QCOMPARE(classA->externalConversionOperators().count(), 1);
+ QCOMPARE(classA->externalConversionOperators().first()->type()->cppSignature(), QString("A"));
+ QCOMPARE(classA->externalConversionOperators().first()->ownerClass()->name(), QString("B"));
+ QCOMPARE(classA->implicitConversions().count(), 1);
+ QCOMPARE(classA->implicitConversions().first()->type()->cppSignature(), QString("A"));
+ QCOMPARE(classA->implicitConversions().first()->ownerClass()->name(), QString("B"));
+}
+
+void TestConversionOperator::testConversionOperatorReturningConstReference()
+{
+ const char cppCode[] = "\
+ struct A {};\
+ struct B {\
+ operator const A&() const;\
+ };";
+ const char xmlCode[] = "\
+ <typesystem package='Foo'>\
+ <value-type name='A' />\
+ <value-type name='B' />\
+ </typesystem>";
+
+ TestUtil t(cppCode, xmlCode);
+ AbstractMetaClassList classes = t.builder()->classes();
+ AbstractMetaClass* classA = classes.findClass("A");
+ AbstractMetaClass* classB = classes.findClass("B");
+ QVERIFY(classA);
+ QVERIFY(classB);
+ QCOMPARE(classA->functions().count(), 2);
+ QCOMPARE(classB->functions().count(), 3);
+ QCOMPARE(classA->externalConversionOperators().count(), 1);
+ QCOMPARE(classA->externalConversionOperators().first()->type()->cppSignature(), QString("A"));
+ QCOMPARE(classA->externalConversionOperators().first()->ownerClass()->name(), QString("B"));
+ QCOMPARE(classA->implicitConversions().count(), 1);
+ QCOMPARE(classA->implicitConversions().first()->type()->cppSignature(), QString("A"));
+ QCOMPARE(classA->implicitConversions().first()->ownerClass()->name(), QString("B"));
+}
+
QTEST_APPLESS_MAIN(TestConversionOperator)
#include "testconversionoperator.moc"
diff --git a/tests/testconversionoperator.h b/tests/testconversionoperator.h
index 25b8d8c2..a901f309 100644
--- a/tests/testconversionoperator.h
+++ b/tests/testconversionoperator.h
@@ -32,6 +32,8 @@ private slots:
void testConversionOperator();
void testConversionOperatorOfDiscardedClass();
void testRemovedConversionOperator();
+ void testConversionOperatorReturningReference();
+ void testConversionOperatorReturningConstReference();
};
#endif