From 918ac217df662fcb0865dba278df9151c3665fbc Mon Sep 17 00:00:00 2001 From: Yuriy Solodkyy Date: Thu, 20 Apr 2017 12:47:35 -0700 Subject: [PATCH] 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 --- src/mongo/util/lru_cache.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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); } /**