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++/16293] New: __attribute__(([non-]const)): optimization bug?


int global_var = 0; 
 
class A { 
public: 
    int foo(const char* const ptr) const 
    { 
#ifdef DO_ERRORS 
        ptr++; 
        *ptr = 'x'; 
        tmp = *ptr; 
#endif 
        return 1; 
    } 
    int bar_const() __attribute__((const)) 
    { 
        return 1; 
    } 
    int bar_nonconst() 
    { 
        global_var++; 
        return 1; 
    } 
    int bar_test() 
    { 
        int val = 0; 
        if (0 && bar_const()) 
            val++; 
        if (0 && bar_nonconst()) 
            val++; 
        return val; 
    } 
protected: 
    char tmp; 
}; 
 
int main(int, char**) 
{ 
    A a; 
    a.bar_test(); 
    return global_var; 
} 
 
# g++ -Wall const.cpp -o const && ./const 
# echo $? 
0 
^^ I've expected global_var == 1.

-- 
           Summary: __attribute__(([non-]const)): optimization bug?
           Product: gcc
           Version: 3.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pluto at pld-linux dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: pentium3-pld-linux
  GCC host triplet: pentium3-pld-linux
GCC target triplet: pentium3-pld-linux


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


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