[Bug c++/11512] New: Wrong warning in trivial function template
jan at etpmod dot phys dot tue dot nl
gcc-bugzilla@gcc.gnu.org
Sun Jul 13 13:32:00 GMT 2003
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11512
Summary: Wrong warning in trivial function template
Product: gcc
Version: 3.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jan at etpmod dot phys dot tue dot nl
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: linux, glibc-2.2.5
GCC host triplet: linux, glibc-2.2.5
GCC target triplet: linux, glibc-2.2.5
Consider the following code. When compiling with -Wall it generates:
comma.cpp: In function `int foo2()':
comma.cpp:15: warning: left-hand operand of comma expression has no effect
The 'identical' template-less function (foo1) compiles without warnings. Obviously this warning
is wrong, and both versions of the code give the expected result.
#include <cassert>
int foo1()
{
int r=0;
for (int i=0; i<1; ++i, ++r)
;
return r;
}
template <class T>
int foo2()
{
int r=0;
for (int i=0; i<1; ++i, ++r)
;
return r;
}
int main()
{
assert(foo1()==1);
assert(foo2<int>()==1);
return 0;
}
More information about the Gcc-bugs
mailing list