c++11 - Is this a Visual Studio 2013 update 4 C++ optimizer bug or is my code wrong? -


i have been seeing crashes in our software since updated boost 1.58 , vs2013. when compiler optimization on see crashes. boost 1.55 there no crashes. i've managed isolate problem i'm seeing boost::any_range , how use it.

see example code below:

#include <boost/range/any_range.hpp> #include <boost/range/adaptor/transformed.hpp> #include <vector> #include <memory> #include <cstdio>  class dummyelement { public:     float f_; };  using elementrange = boost::any_range < dummyelement*, boost::bidirectional_traversal_tag >;  using dummyelementuptr = std::unique_ptr < dummyelement > ;  class boostanytest { public:     boostanytest()     {          (int = 0; < 10; ++i)         {             auto element = dummyelementuptr(new dummyelement());             _tprintf(_t("boostanytest::ctor() 0x%p\n"), element.get());              c_.emplace_back(std::tuple<int, dummyelementuptr>(i, std::move(element)));         }     }  public:     elementrange getall();  private:     using _containertype = std::vector < std::tuple<int, std::unique_ptr<dummyelement>> > ;     _containertype    c_; };   elementrange boostanytest::getall() {     auto transform = [ ] (const _containertype::value_type& v) -> dummyelement*     {         return std::get<1>(v).get();     };      return c_ | boost::adaptors::transformed(transform); }   int main() {     boostanytest    any;      auto range = any.getall();      std::for_each(std::begin(range), std::end(range), [ ] (dummyelement* element)     {          _tprintf(_t("testboostanyrange() 0x%p\n"), element);     }); } 

below program output. debug version output expect, optimized release version mistery me @ moment...

debug version output: boostanytest::ctor() 0x007d0fb0 boostanytest::ctor() 0x007d0e30 boostanytest::ctor() 0x007d0e60 boostanytest::ctor() 0x007d1160 boostanytest::ctor() 0x007d0e90 boostanytest::ctor() 0x007d10a0 boostanytest::ctor() 0x007d0f80 boostanytest::ctor() 0x007d0fe0 boostanytest::ctor() 0x007d1010 boostanytest::ctor() 0x007d1040 testboostanyrange() 0x007d0fb0 testboostanyrange() 0x007d0e30 testboostanyrange() 0x007d0e60 testboostanyrange() 0x007d1160 testboostanyrange() 0x007d0e90 testboostanyrange() 0x007d10a0 testboostanyrange() 0x007d0f80 testboostanyrange() 0x007d0fe0 testboostanyrange() 0x007d1010 testboostanyrange() 0x007d1040  release version output: boostanytest::ctor() 0x00bfa358 boostanytest::ctor() 0x00bfa238 boostanytest::ctor() 0x00bfa3e8 boostanytest::ctor() 0x00bfa248 boostanytest::ctor() 0x00bfa258 boostanytest::ctor() 0x00bfa268 boostanytest::ctor() 0x00c2ecb8 boostanytest::ctor() 0x00c2ed98 boostanytest::ctor() 0x00c2eda8 boostanytest::ctor() 0x00c2ed48 testboostanyrange() 0x00a5fce0 testboostanyrange() 0x00a5fce0 testboostanyrange() 0x00a5fce0 testboostanyrange() 0x00a5fce0 testboostanyrange() 0x00a5fce0 testboostanyrange() 0x00a5fce0 testboostanyrange() 0x00a5fce0 testboostanyrange() 0x00a5fce0 testboostanyrange() 0x00a5fce0 testboostanyrange() 0x00a5fce0 

maybe code wrong or bug in optimizer? tips appreciated!

this boost bug 10493 (introduced in boost 1.56, why code works boost 1.55).

the workaround use t const reference template parameter, in case:

using elementrange = boost::any_range <     dummyelement*,     boost::bidirectional_traversal_tag,     dummyelement* const >; 

example.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -