# False Positive Warning

I have some problems with automatic warnings after package updates. Our group created a package (TDAvec) and recently I have submitted the update. This submission was rejected with the warning

VPB.cpp:51:13: warning: use of bitwise '&' with boolean operands [-Wbitwise-instead-of-logical]

This warning is very likely to be false positive, since in the considered line we are working with two LogicalVector, logical `and` for them is single &. I have replied to the email with the explanation, but the package on CRAN is not updated for some of the platforms.

Could you please tell me, what should I do in this case?

That error is generally about where the comparison is being used. For example, perhaps this is inside an `if`? You might want `all(thing1 & thing2)`. If that doesn't sound right, can you share a bit more code?

Edit: welcome to the community! I hope you find it a helpful experience!

Thank you very much for the reply!

The problem, that we are trying to solve, is the following. There are three numeric vectors of the same size (say, `y`, `a`, and `b`), we need the indices of the elements, for which a[i] <= y[i] <= b[i]. In R this should look as simple as

``````which( (a<=y) & (y<=b))
``````

In Rcpp version of the code we have created a cpp partner of the `which` function

``````IntegerVector which_C(LogicalVector vec)
``````

This function is called as

``````which_C( (a<=y) & (y<=b))
``````

where `a`, `b`, `y` are `NumericVector`s of the same size. My understanding is that here `a<=y` and `y<=b` will both be `LogicalVector`s, so `(a<=y) & (y<=b)` (with only one ampersand) is also a logical vector, and the code above gives what we want. Moreover, the Rcpp code returns exactly the same result as R, so we are sure that the code is correct.

Now the problem is to explain this to the c++ compiler...

Ohhh, I misread your error message! Yeah, it's definitely happening on the C++ side, which means I'm unlikely to be of much help... but I'll try, because I'm trying to refresh my C++ skills!

Does `which_C` work in other cases? And, just checking... is `IntegerVector which_C(LogicalVector vec)` the code at `VPB.cpp:51:13`?

This topic was automatically closed after 45 days. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.