User account creation filtered due to spam.

Bug 14862 - Invalid code generated (possible when reordering instructions)
Summary: Invalid code generated (possible when reordering instructions)
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.3
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2004-04-06 10:42 UTC by Mirek Fidler
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Mirek Fidler 2004-04-06 10:42:21 UTC
gcc (GCC) 3.3.3 (mingw special)
gcc (GCC) 3.3.1 (mingw special 20030804-1)

This code produces invalid output:

#include <iostream>

struct Bar {
	int x;
	int y;

struct Foo {
	int a;
	int b;

	operator Bar() const { return *(Bar *)this; }

int main(int argc, const char **argv)
	Foo f;
	f.a = 12345;
	f.b = 54321;
	Bar b = f;
	std::cout << b.x << ", " << b.y << '\n';

	return 0;

when compiled with options

-c -O2 -ffunction-sections
Comment 1 Stephan T. Lavavej 2004-04-06 11:23:41 UTC
I'm pretty sure that 14882 2003 3.10 15 places this program squarely in nasal 
demon territory.
Comment 2 Andrew Pinski 2004-04-06 11:44:24 UTC
Invalid as you are braking aliasing rules by using the cast to (Bar *) from "Foo*".
Comment 3 Giovanni Bajo 2004-04-06 12:11:56 UTC
Use -fno-strict-aliasing if your program relies on this, but you will miss 
useful optimizations. The right way is to fix your code.
Comment 4 Andrew Pinski 2005-06-05 08:44:29 UTC
Reopening to ...
Comment 5 Andrew Pinski 2005-06-05 08:44:46 UTC
Mark as a dup of bug 21920.

*** This bug has been marked as a duplicate of 21920 ***