chromium/base/time/time.h:690:37: error: possible misuse of comma operator here [-Werror,-Wcomma] |
|||
Issue description
Chrome Version: N/A (Trunk source code)
OS: Ubuntu
What steps will reproduce the problem?
* Compile Firefox (which includes some Chromium headers) using clang version 5.0.0 (trunk 304217)
* OR, I expect you can trigger the same issue by building Chrome with "-Wcomma" build warning manually added wherever you add build warnings.
What is the expected result?
Successful build; expecting no Wcomma build warning for base/time/time.h
What happens instead?
This build warning (treated as an error in my build configuration):
==================
chromium/base/time/time.h:690:37: error: possible misuse of comma operator here [-Werror,-Wcomma]
DCHECK(positive_value > 0),
^
chromium/base/time/time.h:690:11: note: cast expression to void to silence warning
DCHECK(positive_value > 0),
^~~~~~~~~~~~~~~~~~~~~~~~~~
static_cast<void>( )
chromium/base/logging.h:702:3: note: expanded from macro 'DCHECK'
LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chromium/base/logging.h:364:3: note: expanded from macro 'LAZY_STREAM'
!(condition) ? (void) 0 : ::logging::LogMessageVoidify() & (stream)
^
1 error generated.
==================
Please use labels and text to provide additional information.
The comma operator is tricky because it discards the result of its first operand. Clang is wanting to be stricter & make developers opt into that behavior more clearly by wrapping the discarded operand in a "(void)" cast, if that's the behavior the developer really wants.
Here, it looks like that's the behavior that Chromium wants (at least, it looks like this code was added[1] & then rewritten[2] relatively recently, so I don't think it's a mistake). So it would be great if the chromium source code could take clang's advice here and use a "(void)" cast, to make the discarding clearer & to suppress the build warning. This will benefit Firefox as well, once we at Mozilla import an updated snapshot of this header down the line. :)
[1] https://chromium.googlesource.com/chromium/src/+/bad4e03c815490e4eb8ceef9b5143b58c6fefb81%5E%21/base/time/time.h
(see "DCHECK(positive_value > 0)," at very bottom of that page)
[2] https://chromium.googlesource.com/chromium/src/+/9ca6e2937f3f435d527f601aeae2e220355d4155%5E%21/base/time/time.h
,
Jun 2 2017
,
Jun 2 2017
(For the record, I've also filed https://bugzilla.mozilla.org/show_bug.cgi?id=1369837 to work around this in Firefox by applying the attached patch over there, until this has been resolved in the upstream Chromium source code.)
,
Jun 9 2017
A patch was applied to FireFox's use of the chromium header the other day. miu@ can you look at whether we can do this on the ToT branch itself?
,
Jan 25 2018
This was fixed: commit fb3a33751c190240b64a1b22feee6704c2a822bc [log] [tgz] author Will Harris <wfh@chromium.org> Tue Sep 26 07:15:24 2017 committer Commit Bot <commit-bot@chromium.org> Tue Sep 26 07:15:24 2017 tree 636752d3440dc3122d237be47c76fc3b8a162fbb parent 13cf640a354a2b3dd733b63ce157bc5141e52773 [diff] Remove an MSVC analyze workaround. Also, move the DCHECK out of the comma operator. |
|||
►
Sign in to add a comment |
|||
Comment 1 by dholb...@gmail.com
, Jun 2 2017