| 2672 | } |
| 2673 | |
| 2674 | void TestDUChain::testValueDependentBitWidth() |
| 2675 | { |
| 2676 | if (QVersionNumber::fromString(ClangHelpers::clangVersion()) < QVersionNumber(17, 0, 0)) { |
| 2677 | QSKIP("Parsing value-dependent bit-fields may cause an assertion failure or a crash in libclang version < 17"); |
| 2678 | } |
| 2679 | |
| 2680 | TestFile file(QStringLiteral(R"( |
| 2681 | #include <climits> |
| 2682 | |
| 2683 | template<class T, unsigned I> |
| 2684 | struct Str { |
| 2685 | typedef typename T::size_type size_type; |
| 2686 | |
| 2687 | int w : sizeof(double); |
| 2688 | int x : sizeof(T); |
| 2689 | short y : I + 1; |
| 2690 | unsigned length1 : (sizeof(size_type)*CHAR_BIT - 1); |
| 2691 | size_type length2 : (sizeof(size_type)*CHAR_BIT - 1); |
| 2692 | size_type z = 5; |
| 2693 | }; |
| 2694 | )"), |
| 2695 | QStringLiteral("cpp")); |
| 2696 | |
| 2697 | QVERIFY(file.parseAndWait()); |
| 2698 | { |
| 2699 | DUChainReadLocker lock; |
| 2700 | QVERIFY(file.topContext()); |
| 2701 | QCOMPARE(file.topContext()->localDeclarations().size(), 1); |
| 2702 | QCOMPARE(file.topContext()->childContexts().size(), 1); |
| 2703 | |
| 2704 | const auto strContext = file.topContext()->childContexts().constFirst(); |
| 2705 | QVERIFY(strContext); |
| 2706 | QCOMPARE(strContext->type(), DUContext::Class); |
| 2707 | QCOMPARE(strContext->childContexts().size(), 0); |
| 2708 | |
| 2709 | const auto strDeclarations = strContext->localDeclarations(); |
| 2710 | QCOMPARE(strDeclarations.size(), 9); |
| 2711 | |
| 2712 | const auto varW = dynamic_cast<const ClassMemberDeclaration*>(strDeclarations.at(3)); |
| 2713 | QVERIFY(varW); |
| 2714 | QCOMPARE(varW->bitWidth(), sizeof(double)); |
| 2715 | |
| 2716 | for (int i = 4; i < strDeclarations.size() - 1; ++i) { |
| 2717 | const auto member = dynamic_cast<const ClassMemberDeclaration*>(strDeclarations.at(i)); |
| 2718 | QVERIFY(member); |
| 2719 | QCOMPARE(member->bitWidth(), ClassMemberDeclaration::ValueDependentBitWidth); |
| 2720 | } |
| 2721 | |
| 2722 | const auto varZ = dynamic_cast<const ClassMemberDeclaration*>(strDeclarations.constLast()); |
| 2723 | QVERIFY(varZ); |
| 2724 | QCOMPARE(varZ->bitWidth(), ClassMemberDeclaration::NotABitField); |
| 2725 | } |
| 2726 | } |
| 2727 | |
| 2728 | void TestDUChain::testBitWidthUpdate() |
| 2729 | { |
nothing calls this directly
no test coverage detected