Skip to content

Use logical and for boolean operation in bstr#67858

Merged
AaronRobinsonMSFT merged 1 commit intodotnet:mainfrom
omajid:pal-bstr-boolean-bitwise-and
Apr 11, 2022
Merged

Use logical and for boolean operation in bstr#67858
AaronRobinsonMSFT merged 1 commit intodotnet:mainfrom
omajid:pal-bstr-boolean-bitwise-and

Conversation

@omajid
Copy link
Member

@omajid omajid commented Apr 11, 2022

This seems like a mistake and recent versions of clang even complain
about it:

/runtime/src/coreclr/palrt/bstr.cpp:50:13: error: use of bitwise '&' with boolean operands [-Werror,-Wbitwise-instead-of-logical]
        if (SUCCEEDED(ULongMult(cchSize, sizeof(WCHAR), &temp)) &
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                                &&
/runtime/src/coreclr/pal/inc/pal.h:5144:27: note: expanded from macro 'SUCCEEDED'
#define SUCCEEDED(Status) ((HRESULT)(Status) >= 0)
                          ^
/runtime/src/coreclr/palrt/bstr.cpp:50:13: note: cast one or both operands to int to silence this warning
/runtime/src/coreclr/pal/inc/pal.h:5144:27: note: expanded from macro 'SUCCEEDED'
#define SUCCEEDED(Status) ((HRESULT)(Status) >= 0)
                          ^
1 error generated.

Seen with Clang 14:

# clang -v
clang version 14.0.0 (Fedora 14.0.0-1.fc37)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/12
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/12
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

This seems like a mistake and recent versions of clang even complain
about it:

    /runtime/src/coreclr/palrt/bstr.cpp:50:13: error: use of bitwise '&' with boolean operands [-Werror,-Wbitwise-instead-of-logical]
            if (SUCCEEDED(ULongMult(cchSize, sizeof(WCHAR), &temp)) &
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                                    &&
    /runtime/src/coreclr/pal/inc/pal.h:5144:27: note: expanded from macro 'SUCCEEDED'
    #define SUCCEEDED(Status) ((HRESULT)(Status) >= 0)
                              ^
    /runtime/src/coreclr/palrt/bstr.cpp:50:13: note: cast one or both operands to int to silence this warning
    /runtime/src/coreclr/pal/inc/pal.h:5144:27: note: expanded from macro 'SUCCEEDED'
    #define SUCCEEDED(Status) ((HRESULT)(Status) >= 0)
                              ^
    1 error generated.
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Apr 11, 2022
@ghost
Copy link

ghost commented Apr 11, 2022

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@AaronRobinsonMSFT AaronRobinsonMSFT merged commit 8227bb7 into dotnet:main Apr 11, 2022
@ghost ghost locked as resolved and limited conversation to collaborators May 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-PAL-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants