Tpetra: Build warnings in test suggest incorrectness
Created by: mhoemmen
@trilinos/tpetra
When I build current Trilinos develop with Clang on Mac, I get many errors in MultiVector_UnitTests.cpp
that look like this:
.../Trilinos/packages/tpetra/core/test/MultiVector/MultiVector_UnitTests.cpp:2180:69: warning: expression result unused [-Wunused-value]
os << ", B.modified_device: " << B_dv.need_sync_host ()?1:0;
^
.../Trilinos/packages/tpetra/core/test/MultiVector/MultiVector_UnitTests.cpp:2176:68: warning: operator '?:' has lower precedence than
'<<'; '<<' will be evaluated first [-Wparentheses]
os << ": A.modified_host: " << A_dv.need_sync_device ()?1:0;
That latter warning suggests that code that looks like the above might not be doing what people think. In particular, I suspect that it does the following:
- Evaluates
os << ": A.modified_host: " << A_dv.need_sync_device ()
, which returnsstd::ostream&
. - Evaluates
(std::ostream::operator bool()) ? 1 : 0
, which should always return 1 if the stream is valid.
This is certainly not what the author intended. This should be easy to fix: Just parenthesize the trinary operator invocations.