Andrew Truckle
Andrew Truckle

Reputation: 19117

Toggling a bool value is being flagged in the Visual Studio IDE

Take this simple code:

void CChristianLifeMinistryEditorDlg::OnOptionsAddTimeToConcludingComments()
{
    BOOL bAddTime = CChristianLifeMinistryUtils::AddRemainingTimeToConcludingComments();
    bAddTime = !bAddTime;
    CChristianLifeMinistryUtils::SetAddRemainingTimeToConcludingComments(bAddTime);

    UpdateMenuGUI();
    SetModified(true);
}

The !bAddTime is being flagged:

enter image description here

It says:

Using logical '!' when bitwise '~' was probably intended.

I have used this technique before to toggle boolean values it appears to operate correctly. So why the warning? It is not related to Visual Assist.

Upvotes: 1

Views: 77

Answers (1)

IInspectable
IInspectable

Reputation: 51413

Simply change

BOOL bAddTime = ...

to

bool bAddTime = ...

I guess the static code analysis gets confused by BOOL being a type alias for int.

Upvotes: 3

Related Questions