[Boost-users] Crash in VS2013, bug in compiler, boost or my code ? (flyweight, variant and initializer list)

34 views
Skip to first unread message

Olivier Tristan

unread,
Dec 13, 2013, 12:16:09 PM12/13/13
to boost...@lists.boost.org
Hello Boost users,

Using the following sample code I have some crash in VS2013 but it works
fine in LLVM on OSX
Is this is a mistake on my side or an issue elsewhere ?

#include <string>
#include <cstdint>
#include <vector>
#include <boost/flyweight/flyweight.hpp>
#include <boost/flyweight/no_tracking.hpp>
#include <boost/flyweight/static_holder.hpp>
#include <boost/flyweight/set_factory.hpp>
#include <boost/flyweight/simple_locking.hpp>
#include <boost/variant.hpp>

typedef boost::flyweights::flyweight<
std::string,
boost::flyweights::no_tracking,
boost::flyweights::set_factory<>,
boost::flyweights::static_holder,
boost::flyweights::simple_locking
> string_flyweight;


typedef boost::variant<
bool,
double,
string_flyweight
> Variant;


int main(void)
{
std::vector<Variant> v = { 1., true, string_flyweight("toto") };
return 0;
}

Thanks,


--
Olivier TRISTAN
uvi.net
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Andreas M. Iwanowski

unread,
Dec 13, 2013, 5:54:08 PM12/13/13
to boost...@lists.boost.org
Care to define "crash"?

If the compiler "crashes" (i.e. access violates; internal compiler error et. al.), then it is always a compiler bug; A compiler shouldn't choke on the input.

Mit freundlichen Grüßen / With best regards

Andreas Iwanowski - IT Administrator / Software Developer
www.awato.de | name...@afim.info
T: +49 (0)2133 26031 55 | F: +49 (0)2133 26031 01
awato Software GmbH | Salm Reifferscheidt Allee 37 | D-41540 Dormagen

avisor-Support | T: +49 (0)621 6094 043 | F: +49 (0)621 6071 447

Geschäftsführer: Ursula Iwanowski | HRB: Neuss 7208 | VAT-no.: DE 122796158

Lars Viklund

unread,
Dec 13, 2013, 6:27:20 PM12/13/13
to boost...@lists.boost.org
On Fri, Dec 13, 2013 at 10:54:08PM +0000, Andreas M. Iwanowski wrote:
> Care to define "crash"?
>
> If the compiler "crashes" (i.e. access violates; internal compiler error et. al.), then it is always a compiler bug; A compiler shouldn't choke on the input.

It seems to be a runtime failure during post-main shutdown, not an ICE.
Stack trace follows:
====8<====
testbed2013-hz.exe!std::_Tree<std::_Tset_traits<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type>,0> >::_Orphan_ptr(std::_Tree<std::_Tset_traits<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type>,0> > & _Cont, std::_Tree_node<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type,void *> * _Ptr) Line 221
8 C++
testbed2013-hz.exe!std::_Tree<std::_Tset_traits<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type>,0> >::clear() Line 1540 C++
testbed2013-hz.exe!std::_Tree<std::_Tset_traits<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type>,0> >::erase(std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type> > > _First, std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type> > > _Last) Line 1515 C++
testbed2013-hz.exe!std::_Tree<std::_Tset_traits<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type>,0> >::_Tidy() Line 2230 C++
testbed2013-hz.exe!std::_Tree<std::_Tset_traits<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type>,0> >::~_Tree<std::_Tset_traits<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type>,0> >() Line 1193 C++
testbed2013-hz.exe!std::set<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type> >::~set<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type> >() C++
testbed2013-hz.exe!boost::flyweights::assoc_container_factory_class<std::set<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type> > >::~assoc_container_factory_class<std::set<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type> > >() C++
testbed2013-hz.exe!boost::flyweights::set_factory_class<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,boost::mpl::na,boost::mpl::na>::~set_factory_class<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::rep_type,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,boost::mpl::na,boost::mpl::na>() C++
testbed2013-hz.exe!boost::flyweights::detail::flyweight_core<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,boost::mpl::na,boost::flyweights::no_tracking,boost::flyweights::set_factory<boost::mpl::na,boost::mpl::na,0>,boost::flyweights::simple_locking,boost::flyweights::static_holder>::holder_arg::~holder_arg() C++
> testbed2013-hz.exe!`boost::flyweights::static_holder_class<boost::flyweights::detail::flyweight_core<boost::flyweights::detail::default_value_policy<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,boost::mpl::na,boost::flyweights::no_tracking,boost::flyweights::set_factory<boost::mpl::na,boost::mpl::na,0>,boost::flyweights::simple_locking,boost::flyweights::static_holder>::holder_arg>::get'::`2'::`dynamic atexit destructor for 'c''() C++
msvcr120d.dll!doexit(int code, int quick, int retcaller) Line 628 C
msvcr120d.dll!exit(int code) Line 417 C
testbed2013-hz.exe!__tmainCRTStartup() Line 662 C
testbed2013-hz.exe!mainCRTStartup() Line 466 C
kernel32.dll!@BaseThreadInitThunk@12() Unknown
ntdll.dll!__RtlUserThreadStart() Unknown
ntdll.dll!__RtlUserThreadStart@8() Unknown
====8<====

Andreas M. Iwanowski

unread,
Dec 13, 2013, 7:30:31 PM12/13/13
to boost...@lists.boost.org
Hello Lars, Hello Olivier;

I have a suspicion that this may be with the initializer list; I do not have VS2013 handy.

However, without initializer list and using push_back(), it compiles and runs without crash on both VS2010 and mingw gcc 3.4.2.
Could you try that maybe?


Mit freundlichen Grüßen / With best regards

Andreas Iwanowski - IT Administrator / Software Developer
www.awato.de | name...@afim.info
T: +49 (0)2133 26031 55 | F: +49 (0)2133 26031 01
awato Software GmbH | Salm Reifferscheidt Allee 37 | D-41540 Dormagen

avisor-Support | T: +49 (0)621 6094 043 | F: +49 (0)621 6071 447

Geschäftsführer: Ursula Iwanowski | HRB: Neuss 7208 | VAT-no.: DE 122796158


-----Original Message-----

Lars Viklund

unread,
Dec 13, 2013, 7:38:14 PM12/13/13
to boost...@lists.boost.org
On Sat, Dec 14, 2013 at 12:30:31AM +0000, Andreas M. Iwanowski wrote:
> Hello Lars, Hello Olivier;
>
> I have a suspicion that this may be with the initializer list; I do not have VS2013 handy.
>
> However, without initializer list and using push_back(), it compiles and runs without crash on both VS2010 and mingw gcc 3.4.2.
> Could you try that maybe?

Hi,
Given OP's test case and replacing the vector initialization with three
calls to push_back (or emplace_back, no difference) the program does not
crash on shutdown.

I forgot to mention the address that the access violation triggered on
in my repro run is "Access violation reading location 0xCCCCCCD4.", so
an offset into "uninitialized stack memory" it seems.

(Also note that the Boost list doesn't do top-posting, replies go
in-line after the sections they refer to.)
--
Lars Viklund | z...@acc.umu.se

Michael Powell

unread,
Dec 13, 2013, 7:43:07 PM12/13/13
to boost...@lists.boost.org
On Fri, Dec 13, 2013 at 6:38 PM, Lars Viklund <z...@acc.umu.se> wrote:
> On Sat, Dec 14, 2013 at 12:30:31AM +0000, Andreas M. Iwanowski wrote:
>> Hello Lars, Hello Olivier;
>>
>> I have a suspicion that this may be with the initializer list; I do not have VS2013 handy.
>>
>> However, without initializer list and using push_back(), it compiles and runs without crash on both VS2010 and mingw gcc 3.4.2.
>> Could you try that maybe?
>
> Hi,
> Given OP's test case and replacing the vector initialization with three
> calls to push_back (or emplace_back, no difference) the program does not
> crash on shutdown.

Probably related to this: it's appears to be a known (and pretty
serious IMO) bug in the compiler.

http://connect.microsoft.com/VisualStudio/feedback/details/800104/

The report has to do with CString, but an SO blog explains how the
compiler is treating temporaries.

http://stackoverflow.com/questions/19269345/initializing-map-of-maps-with-initializer-list-in-vs-2013

Plausible workaround: avoid initializer lists, especially of VS20XX is
your target.

Other than that, HTH and good luck.

Andreas M. Iwanowski

unread,
Dec 13, 2013, 8:03:20 PM12/13/13
to boost...@lists.boost.org
>Probably related to this: it's appears to be a known (and pretty serious IMO) bug in the compiler.
>http://connect.microsoft.com/VisualStudio/feedback/details/800104/
>The report has to do with CString, but an SO blog explains how the compiler is treating temporaries.
>http://stackoverflow.com/questions/19269345/initializing-map-of-maps-with-initializer-list-in-vs-2013
>Plausible workaround: avoid initializer lists, especially of VS20XX is your target.
>Other than that, HTH and good luck.

+1 for digging this out.
This is a really nasty compiler bug indeed.
It would indeed make sense, since string_flyweight is the complex type where the compiler would trash the memory.
You could try with other types just to verify, but this indeed seems to be the compiler's fault and not yours.


Mit freundlichen Grüßen / With best regards

Andreas Iwanowski - IT Administrator / Software Developer
www.awato.de | name...@afim.info
T: +49 (0)2133 26031 55 | F: +49 (0)2133 26031 01
awato Software GmbH | Salm Reifferscheidt Allee 37 | D-41540 Dormagen

avisor-Support | T: +49 (0)621 6094 043 | F: +49 (0)621 6071 447

Geschäftsführer: Ursula Iwanowski | HRB: Neuss 7208 | VAT-no.: DE 122796158

Joaquín Mª López Muñoz

unread,
Dec 14, 2013, 7:30:08 AM12/14/13
to boost...@lists.boost.org
El 14/12/2013 2:03, Andreas M. Iwanowski escribió:
>> Probably related to this: it's appears to be a known (and pretty serious IMO) bug in the compiler.
>> http://connect.microsoft.com/VisualStudio/feedback/details/800104/
>> The report has to do with CString, but an SO blog explains how the compiler is treating temporaries.
>> http://stackoverflow.com/questions/19269345/initializing-map-of-maps-with-initializer-list-in-vs-2013
>> Plausible workaround: avoid initializer lists, especially of VS20XX is your target.
>> Other than that, HTH and good luck.
> +1 for digging this out.
> This is a really nasty compiler bug indeed.
> It would indeed make sense, since string_flyweight is the complex type where the compiler would trash the memory.
> You could try with other types just to verify, but this indeed seems to be the compiler's fault and not yours.
>

I haven't tried, but maybe replacing the problematic initialization with

std::vector<Variant> v = { 1., true, "toto"};

can work around the compiler bug (can't try myself), in case it helps
somehow.

Joaquín M López Muñoz
Telefónica Digital

________________________________

Este mensaje se dirige exclusivamente a su destinatario. Puede consultar nuestra política de envío y recepción de correo electrónico en el enlace situado más abajo.
This message is intended exclusively for its addressee. We only send and receive email on the basis of the terms set out at:
http://www.tid.es/ES/PAGINAS/disclaimer.aspx

Olivier Tristan

unread,
Dec 16, 2013, 3:40:41 AM12/16/13
to boost...@lists.boost.org
Hi Guys,

Declaring the flyweight outside the bracket fixes the crash.

This is indeed this issue
http://connect.microsoft.com/VisualStudio/feedback/details/800104/

Just need to wait for the update now :)

Thanks to all of you for your feedback

Regards,

--
Olivier TRISTAN
uvi.net
Reply all
Reply to author
Forward
0 new messages