This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/11512] New: Wrong warning in trivial function template
- From: "jan at etpmod dot phys dot tue dot nl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 13 Jul 2003 13:32:48 -0000
- Subject: [Bug c++/11512] New: Wrong warning in trivial function template
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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;
}