MCPcopy Create free account
hub / github.com/KDE/kdevelop / testAutoTypeDeduction

Method testAutoTypeDeduction

plugins/clang/tests/test_duchain.cpp:577–612  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

575}
576
577void TestDUChain::testAutoTypeDeduction()
578{
579 TestFile file(QStringLiteral(R"(
580 const volatile auto foo = 5;
581 template<class T> struct myTemplate {};
582 myTemplate<myTemplate<int>& > templRefParam;
583 auto autoTemplRefParam = templRefParam;
584 )"), QStringLiteral("cpp"));
585 QVERIFY(file.parseAndWait());
586
587 DUChainReadLocker lock;
588
589 DUContext* ctx = file.topContext().data();
590 QVERIFY(ctx);
591 QCOMPARE(ctx->localDeclarations().size(), 4);
592 QCOMPARE(ctx->findDeclarations(QualifiedIdentifier(u"foo")).size(), 1);
593 Declaration* decl = ctx->findDeclarations(QualifiedIdentifier(QStringLiteral("foo")))[0];
594 QCOMPARE(decl->identifier(), Identifier(u"foo"));
595#if CINDEX_VERSION_MINOR < 31
596 QEXPECT_FAIL("", "No type deduction here unfortunately, missing API in Clang", Continue);
597#endif
598 QVERIFY(decl->type<IntegralType>());
599#if CINDEX_VERSION_MINOR < 31
600 QCOMPARE(decl->toString(), QStringLiteral("const volatile auto foo"));
601#else
602 QCOMPARE(decl->toString(), QStringLiteral("const volatile int foo"));
603#endif
604
605 decl = ctx->findDeclarations(QualifiedIdentifier(QStringLiteral("autoTemplRefParam")))[0];
606 QVERIFY(decl);
607 QVERIFY(decl->abstractType());
608#if CINDEX_VERSION_MINOR < 31
609 QEXPECT_FAIL("", "Auto type is not exposed via LibClang", Continue);
610#endif
611 QCOMPARE(decl->abstractType()->toString(), QStringLiteral("myTemplate< myTemplate< int >& >"));
612}
613
614void TestDUChain::testTypeDeductionInTemplateInstantiation()
615{

Callers

nothing calls this directly

Calls 11

parseAndWaitMethod · 0.80
localDeclarationsMethod · 0.80
findDeclarationsMethod · 0.80
QualifiedIdentifierClass · 0.50
IdentifierFunction · 0.50
dataMethod · 0.45
topContextMethod · 0.45
sizeMethod · 0.45
identifierMethod · 0.45
toStringMethod · 0.45
abstractTypeMethod · 0.45

Tested by

no test coverage detected