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]

"suggest parentheses around assignment used as truth value" warning bug



The file "test.cpp" (attached) uses an assignment as a truth value in three 
places.   However, one of them (where it occurs inside a templated class) does 
not generate a warning.   We just found such a bug in a program here and were 
surprised that the compiler hadn't caught it.

I didn't see any mention of this bug in the 2.95.2 release notes, but if it 
has already been fixed, let me know.

Thanks,

--Josh


--
Josh Wilmes - jwilmes@cisco.com 


jwilmes@jwilmes-sun:~/gcc-bug$ gcc -v
Reading specs from /usr/SD/gnu.dev/lib/gcc-lib/sparc-sun-solaris2.6/2.95.1/specs
gcc version 2.95.1 19990816 (release)
jwilmes@jwilmes-sun:~/gcc-bug$ uname -a
SunOS jwilmes-sun 5.6 Generic_105181-03 sun4u sparc SUNW,Ultra-5_10
jwilmes@jwilmes-sun:~/gcc-bug$ make test
g++ -Wall test.cpp -o test
test.cpp: In method `void anotherclass::amethod()':
test.cpp:18: warning: suggest parentheses around assignment used as truth value
test.cpp: In function `int main(int, char **)':
test.cpp:28: warning: suggest parentheses around assignment used as truth value



template<class T>
class aclass {
    
public:
    void amethod(void) {
        int var;
        if (var = 0)
            return;     
    }   
};

class anotherclass {
    
public:
    void amethod(void) {
        int var;
        if (var = 0)
            return;     
    }   
};




int main (int argc, char* argv[]) {
     int var;
     if (var = 0)
       return 0;     
}

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