diff options
author | Yuriy Solodkyy <yuriysol@microsoft.com> | 2017-04-20 12:47:35 -0700 |
---|---|---|
committer | ADAM David Alan Martin <adam.martin@10gen.com> | 2017-04-24 16:46:04 -0400 |
commit | 918ac217df662fcb0865dba278df9151c3665fbc (patch) | |
tree | f70474238d55c64ac78944af4bb50d08f7ccd510 | |
parent | 57d1ad19ed3169bee7d4479e7cedd468e7f52b64 (diff) | |
download | mongo-918ac217df662fcb0865dba278df9151c3665fbc.tar.gz |
SERVER-28890 Workaround for upcoming `/Zc:ternary`
This workaround allows building MongoDB under Microsoft's upcoming
compiler, with the `/Zc:ternary` option enabled. This option would
be implied by the `/permissive-` option. The code fails to compile
under this mode when using Microsoft's existing `std::list`
implementation. This explicit cast can be removed once Microsoft's
`std::list` stops using inheritance between const and modifiable
iterators.
The issue arises because the `?:` ternary operator requires an
impossible conversion from a `const iterator &` to a
`const_iterator &&` or a `const_iterator &`. This occurs because
Microsoft's `std::list< ... >::iterator` inherits from
`std::list< ... >::const_iterator`. Were the `const iterator &`
non-constant (`iterator &`), this would work. Additionally, were the
`const_iterator &` constant (`const const_iterator &`), this would
also work.
Closes #1147
-rw-r--r-- | src/mongo/util/lru_cache.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/mongo/util/lru_cache.h b/src/mongo/util/lru_cache.h index 5feea1a0bc3..b59f66e262d 100644 --- a/src/mongo/util/lru_cache.h +++ b/src/mongo/util/lru_cache.h @@ -131,7 +131,10 @@ public: */ const_iterator cfind(const K& key) const { auto it = this->_map.find(key); - return (it == this->_map.end()) ? this->end() : it->second; + // TODO(SERVER-28890): Remove the function-style cast when MSVC's + // `std::list< ... >::iterator` implementation doesn't conflict with their `/Zc:ternary` + // flag support . + return (it == this->_map.end()) ? this->end() : const_iterator(it->second); } /** |