为什么会引发代码分析警告 "Using logical && when bitwise & was probably intended"?

Why is code analysis warning "Using logical && when bitwise & was probably intended" being raised?

代码:

BOOL CCreateReportDlg::CanSwapBrothers()
{
    BOOL            b1in2 = FALSE, b2in1 = FALSE;
    CStringArray    aryStrNames;

    // Must have valid data
    if (!IsSwapBrotherInit())
        return FALSE;

    // Get cell pointers
    auto pCell1 = GetSwapBrotherCell(1);
    auto pCell2 = GetSwapBrotherCell(2);
    if (pCell1 != nullptr && pCell2 != nullptr)
    {
        // Look for brother (cell 1) in cell 2 array
        auto strName = pCell1->GetText();
        pCell2->GetOptions(aryStrNames);
        const auto iNumNames = aryStrNames.GetSize();
        for (auto iName = 0; iName < iNumNames; iName++)
        {
            if (aryStrNames[iName] == strName)
            {
                b1in2 = TRUE;
                break;
            }
        }

        if (b1in2)
        {
            // Look for brother (cell 2) in cell 1 array
            auto strName = pCell2->GetText();
            pCell1->GetOptions(aryStrNames);
            const auto iNumNames = aryStrNames.GetSize();
            for (auto iName = 0; iName < iNumNames; iName++)
            {
                if (aryStrNames[iName] == strName)
                {
                    b2in1 = TRUE;
                    break;
                }
            }
        }
    }

    return b1in2 && b2in1;
}

感兴趣的行是 return 语句:

return b1in2 && b2in1;

我收到代码分析警告:

lnt-logical-bitwise-mismatch Using logical && when bitwise & was probably intended.

就我而言,我的代码是正确的。为什么要提出这个问题?

编译器发现 && 适用于整数操作数和结果到整数类型的隐式转换。 BOOL有多个位;它与 built-in 类型 bool.

不同

正如您链接到的页面中所述,“逻辑运算符与整数值一起使用”将导致此警告,并且此处肯定存在这种情况。

“MFC”编码风格在很多方面违反了现代建议,使用 non-standard 布尔类型只是较小的问题之一。 CStringArray 也是一种代码味道,现代 C++ 使用模板化容器并具有强大的操作它们的算法,您永远不应该自己编写搜索代码。