This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/11946] New: fun and merriment with enums as function arguments


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]