[Bug c++/61421] Invalid -O2 optimization breaks program

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jun 5 21:36:00 GMT 2014


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421

--- Comment #12 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to mimamer from comment #11)
> In short form,
> 
> template<class T> class list2
> {
>   public:
> 	struct node {
> 		T	*next;
> 		T	*prev;
> 	};
> 
> 	node	anchor;
> 
>   public:
> 	/* API */
> }
> 
> struct Obj : list2<Obj>::node {
> 	/* obj-specific elements */
> }
> 
> list2<Obj>	main_list;
> 
> So, anchor is of type list2<Obj>::node while Obj is derived from
> list2<Obj>::node.

Oh you are upcasting from node to T but the variable is of node type only and
not T.  So this is invalid because of that.  

You need to use either type node inside the struct node or change anchor to
type T instead.


More information about the Gcc-bugs mailing list