| 575 | } |
| 576 | |
| 577 | void 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 | |
| 614 | void TestDUChain::testTypeDeductionInTemplateInstantiation() |
| 615 | { |
nothing calls this directly
no test coverage detected