| 3793 | } |
| 3794 | |
| 3795 | bool isExhaustiveSwitch(const Token *startbrace) |
| 3796 | { |
| 3797 | if (!startbrace || !Token::simpleMatch(startbrace->previous(), ") {") || startbrace->scope()->type != ScopeType::eSwitch) |
| 3798 | return false; |
| 3799 | const Token *rpar = startbrace->previous(); |
| 3800 | const Token *lpar = rpar->link(); |
| 3801 | |
| 3802 | const Token *condition = lpar->astOperand2(); |
| 3803 | if (!condition->valueType()) |
| 3804 | return true; |
| 3805 | |
| 3806 | bool hasDefault = false; |
| 3807 | const std::set<MathLib::bigint> switchValues = getSwitchValues(startbrace, hasDefault); |
| 3808 | |
| 3809 | if (hasDefault) |
| 3810 | return true; |
| 3811 | |
| 3812 | if (condition->valueType()->type == ValueType::Type::BOOL) |
| 3813 | return switchValues.count(0) && switchValues.count(1); |
| 3814 | |
| 3815 | if (condition->valueType()->isEnum()) { |
| 3816 | const std::vector<Enumerator> &enumList = condition->valueType()->typeScope->enumeratorList; |
| 3817 | return std::all_of(enumList.cbegin(), enumList.cend(), [&](const Enumerator &e) { |
| 3818 | return !e.value_known || switchValues.count(e.value); |
| 3819 | }); |
| 3820 | } |
| 3821 | |
| 3822 | return false; |
| 3823 | } |
| 3824 | |
| 3825 | bool isUnreachableOperand(const Token *tok) |
| 3826 | { |
no test coverage detected