Boost C++ Libraries: Ticket #12595: Unexpected result when using type_erased adaptor to a transformed_range when clang optimizations are enabled https://svn.boost.org/trac10/ticket/12595 <p> If clang optimizations -O1 are enabled, when using type_erased adapter on a transformed_range, the range will yield wrong values. </p> <p> For example: </p> <p> int addOne(int b) { </p> <blockquote> <p> return b + 1; </p> </blockquote> <p> } </p> <p> int main() { </p> <blockquote> <p> std::vector&lt;int&gt; nums{ 1, 2, 3 }; auto result = nums | boost::adaptor::transformed(addOne) | boost::adaptor::type_erased&lt;int, boost::forward_traversal_tag&gt;(); </p> </blockquote> <p> } </p> <p> When printing result, it yielded { 1, 1, 1 } instead of { 2, 3, 4 } when compiling with -O1. It worked as expected with no optimization flags. I am compiling the code with clang++. The version of clang is Apple LLVM version 8.0.0 (clang-800.0.38). And I am using c++11. </p> <p> <a class="ext-link" href="http://stackoverflow.com/questions/40479397/getting-unexpected-result-when-compiling-with-clang-optimization?noredirect=1#comment68203492_40479397"><span class="icon">​</span>http://stackoverflow.com/questions/40479397/getting-unexpected-result-when-compiling-with-clang-optimization?noredirect=1#comment68203492_40479397</a> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12595 Trac 1.4.3 Alfredo Altamirano <fredy.altamirano8@…> Tue, 08 Nov 2016 06:12:49 GMT attachment set https://svn.boost.org/trac10/ticket/12595 https://svn.boost.org/trac10/ticket/12595 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">bug.cpp</span> </li> </ul> <p> C++ code reproducing the code. </p> Ticket