http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48418

           Summary: Bit shift operator >>=
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: lis...@lisp2d.net


int x=1000;
x>>=(sizeof(int)<<3);

x is still 1000

In some cases bit shift operator used with variable (not constant) and compiler
didnot show warning. My opinion is that result must be 0.

Remarked code in my program and code to see what's happened.

/*
ULong::ULong(ULInt    const&x):value2(){
    if(x.uli){
        if(sizeof(unsigned    int)==sizeof(unsigned    long    int)){
            value2.push_back(static_cast<unsigned    int>(x.uli));
            return;}
        UInt    const    ibs(sizeof(unsigned    int)<<3);
        ULInt    x2(x);
        do{
            value2.push_back(static_cast<unsigned    int>(x2.uli));
            (x2.uli)>>=(ibs.ui);
        }while(x2.uli);}}
*/
#include    <iostream>
typedef    struct{unsigned    int    i;}si;
int    main(void){
    unsigned    int    x=1000;
    si    w;
    w.i=sizeof(unsigned    int)<<3;
    std::cout<<"x="<<x<<std::endl;
    x>>=w.i;
    std::cout<<"x>>=w.i -> x="<<x<<std::endl;
    x>>=(sizeof(unsigned    int)<<3);
    std::cout<<"x>>=(sizeof(unsigned    int)<<3) -> x="<<x<<std::endl;
    x>>=32;
    std::cout<<"x>>=32 -> x="<<x<<std::endl;
}

Reply via email to