This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/11946] New: fun and merriment with enums as function arguments
- From: "richard dot kreckel at ginac dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Aug 2003 13:54:32 -0000
- Subject: [Bug c++/11946] New: fun and merriment with enums as function arguments
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11946
Summary: fun and merriment with enums as function arguments
Product: gcc
Version: 3.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: richard dot kreckel at ginac dot de
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
Consider this piece of code:
#include <iostream>
using namespace std;
enum thing {
nothing = 0,
chair = 1,
desk = 2,
shelf = 4,
furniture = chair | desk | shelf
};
bool test1(const thing& t)
{
if (t & shelf != 0)
return true;
return false;
}
bool test2(const thing& t)
{
if (t & shelf)
return true;
return false;
}
int main()
{
cout << test1( furniture ) << endl;
cout << test2( furniture ) << endl;
}
Using ss-3.4-20030813 this first prints out "1" (correctly) and then "0"
(wrongly). Looking at the generated code it becomes apparaent that the if is
completely optimized away in function test2(). This also happens when one
doesn't pass the argument as reference, but as value instead.