[Bug c++/49021] [4.6 regression] BOOST_FOREACH over vector segfaults at runtime

2011-05-23 Thread mimomorin at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49021

Michel MORIN mimomorin at gmail dot com changed:

   What|Removed |Added

 CC||mimomorin at gmail dot com

--- Comment #13 from Michel MORIN mimomorin at gmail dot com 2011-05-23 
09:04:14 UTC ---
(In reply to comment #12)
 This is a bug in BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION.

This was already fixed in boost/trunk, 
and the fix will be released in Boost.1.47. 

For details, please see the following ticket:
[Foreach] Compile-time const rvalue detection fails with gcc 4.6
https://svn.boost.org/trac/boost/ticket/5279


[Bug c++/49021] [4.6 regression] BOOST_FOREACH over vector segfaults at runtime

2011-05-20 Thread mikpe at it dot uu.se
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49021

--- Comment #8 from Mikael Pettersson mikpe at it dot uu.se 2011-05-20 
08:27:39 UTC ---
I'm trying to reduce the preprocessed test case, but since I'm not a C++ person
this might take some time.


[Bug c++/49021] [4.6 regression] BOOST_FOREACH over vector segfaults at runtime

2011-05-20 Thread mikpe at it dot uu.se
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49021

--- Comment #9 from Mikael Pettersson mikpe at it dot uu.se 2011-05-20 
09:05:31 UTC ---
(In reply to comment #8)
 I'm trying to reduce the preprocessed test case, but since I'm not a C++ 
 person
 this might take some time.

Scratch that, the preprocessed code is way too weird for me.


[Bug c++/49021] [4.6 regression] BOOST_FOREACH over vector segfaults at runtime

2011-05-20 Thread redi at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49021

--- Comment #10 from Jonathan Wakely redi at gcc dot gnu.org 2011-05-20 
09:48:42 UTC ---
(In reply to comment #9)
 (In reply to comment #8)
  I'm trying to reduce the preprocessed test case, but since I'm not a C++ 
  person
  this might take some time.
 
 Scratch that, the preprocessed code is way too weird for me.

welcome to Boost MPL!  ;)

there are huge chunks that can be removed (iostreams and locales,
reverse_iterators) but reducing it manually is not easy.

See http://gcc.gnu.org/wiki/A_guide_to_testcase_reduction for a tool to do it
automatically


[Bug c++/49021] [4.6 regression] BOOST_FOREACH over vector segfaults at runtime

2011-05-20 Thread redi at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49021

--- Comment #11 from Jonathan Wakely redi at gcc dot gnu.org 2011-05-20 
13:44:10 UTC ---
Created attachment 24299
  -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=24299
reduced by delta


[Bug c++/49021] [4.6 regression] BOOST_FOREACH over vector segfaults at runtime

2011-05-20 Thread jason at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49021

Jason Merrill jason at gcc dot gnu.org changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
 AssignedTo|unassigned at gcc dot   |jason at gcc dot gnu.org
   |gnu.org |


[Bug c++/49021] [4.6 regression] BOOST_FOREACH over vector segfaults at runtime

2011-05-20 Thread jason at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49021

Jason Merrill jason at gcc dot gnu.org changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution||INVALID

--- Comment #12 from Jason Merrill jason at gcc dot gnu.org 2011-05-20 
21:25:50 UTC ---
This is a bug in BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION.

The GCC bugfix meant that where previously

true ? boost::foreach_detail_::make_probe(getv()) : (getv())

had the type vector, now it has type const vector.

5.16/3 says:

Otherwise (i.e., if E1 or E2 has a nonclass type, or if they both have class
types but the underlying classes are not either the same or one a base class of
the other): E1 can be converted to match E2 if E1 can be implicitly converted
to the type that expression E2 would have if E2 were converted to a prvalue (or
the type it has, if E2 is a prvalue).

const vector cannot be converted to make_probevector, but
make_probevector has an operator vector, so it can be converted to const
vector, so the type of the conditional expression is const vector.

Here's a reduced example:

template class T
void f (T, int);

template class T
void f (T const, ...);

struct A { };
struct B { operator A () const; };

const A g();

int main()
{ 
  f( (true ? B() : g()), 0);
}


[Bug c++/49021] [4.6 regression] BOOST_FOREACH over vector segfaults at runtime

2011-05-19 Thread mikpe at it dot uu.se
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49021

--- Comment #6 from Mikael Pettersson mikpe at it dot uu.se 2011-05-19 
23:37:54 UTC ---
The regression started with r170601:

Author: jason
Date: Tue Mar  1 22:44:35 2011
New Revision: 170601

URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=170601
Log:
PR c++/47851
* call.c (standard_conversion): Provide requested cv-quals on
class rvalue conversion.


[Bug c++/49021] [4.6 regression] BOOST_FOREACH over vector segfaults at runtime

2011-05-19 Thread redi at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49021

Jonathan Wakely redi at gcc dot gnu.org changed:

   What|Removed |Added

 CC||jason at gcc dot gnu.org

--- Comment #7 from Jonathan Wakely redi at gcc dot gnu.org 2011-05-20 
00:11:19 UTC ---
well if the fix for PR 47851 made G++ correct then this could be a bug in
BOOST_FOREACH, but it's hard to know because trying to reduce any MPL code is
pretty tedious!

Jason, any ideas?  do we need to reduce it with delta?


[Bug c++/49021] [4.6 regression] BOOST_FOREACH over vector segfaults at runtime

2011-05-17 Thread mikpe at it dot uu.se
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49021

--- Comment #1 from Mikael Pettersson mikpe at it dot uu.se 2011-05-17 
12:37:52 UTC ---
Created attachment 24260
  -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=24260
test case, preprocessed on x86_64-linux


[Bug c++/49021] [4.6 regression] BOOST_FOREACH over vector segfaults at runtime

2011-05-17 Thread mikpe at it dot uu.se
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49021

--- Comment #2 from Mikael Pettersson mikpe at it dot uu.se 2011-05-17 
12:38:38 UTC ---
Created attachment 24261
  -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=24261
test case, non-preprocessed


[Bug c++/49021] [4.6 regression] BOOST_FOREACH over vector segfaults at runtime

2011-05-17 Thread redi at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49021

--- Comment #3 from Jonathan Wakely redi at gcc dot gnu.org 2011-05-17 
13:52:40 UTC ---
The temporary returned by getv() seems to be destroyed too early, before the
printf that uses it


[Bug c++/49021] [4.6 regression] BOOST_FOREACH over vector segfaults at runtime

2011-05-17 Thread redi at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49021

Jonathan Wakely redi at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2011.05.17 17:24:37
 Ever Confirmed|0   |1

--- Comment #4 from Jonathan Wakely redi at gcc dot gnu.org 2011-05-17 
17:24:37 UTC ---
slightly reduced, but boost/foreach.hpp still includes thousands of lines

in this version vectorT zeros its data member on destruction, so using it
after destruction is obvious

#include boost/foreach.hpp

templatetypename T
struct vector
{
typedef const T* const_iterator;

~vector() { data = T(); }

T data;

const_iterator begin() const { return data; }
const_iterator end() const { return data + 1; }
};

vectorint v = { 1 };

const vectorint *
getv()
{
vectorint * ret = { v.data };
return ret;
}

int
main(int argc, char **argv)
{
BOOST_FOREACH(int *w, getv())
__builtin_printf(%d\n, *w);

return 0;
}


[Bug c++/49021] [4.6 regression] BOOST_FOREACH over vector segfaults at runtime

2011-05-17 Thread redi at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49021

--- Comment #5 from Jonathan Wakely redi at gcc dot gnu.org 2011-05-17 
17:28:44 UTC ---
slightly more reduced

#include boost/foreach.hpp

struct vector
{
typedef int* const* const_iterator;

~vector() { data = 0; }

int* data;

const_iterator begin() const { return data; }
const_iterator end() const { return data + 1; }
};

int v = 1;

const vector
getv()
{
vector ret = { v };
return ret;
}

int
main(int argc, char **argv)
{
BOOST_FOREACH(int *w, getv())
__builtin_printf(%d\n, *w);

return 0;
}