[Bug c++/59231] New: gcc misses [-Werror=sign-compare] when inside a template

2013-11-21 Thread a_mcgurn at yahoo dot co.uk
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59231

Bug ID: 59231
   Summary: gcc misses [-Werror=sign-compare] when inside a
template
   Product: gcc
   Version: 4.8.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: a_mcgurn at yahoo dot co.uk

The following code:

--- //filename 
#include 

template
bool equals( X x, Y y )
{
return (x == y);
}

int main()
{
   std::cout << "Hello World!" << std::endl;
   size_t x = 2;
   signed int y = 2;

   if(!equals( x, y ))
   {
  std::cout << "Hello World again - x == y !" << std::endl;
   }

   return 0;
}
---

This produces for g++-4.8.2:

bfs-dl360g7-27$ g++ --std=c++11 -Wall helloWorld.cpp -o helloWorld
NO warnings

for g++-4.4.7 it correctly warns on the 'signed == unsigned long' as incorrect:

bfs-dl360g7-27$ /usr/bin/g++ -Wall helloWorld.cpp -o helloWorld
helloWorld.cpp: In function âbool equals(X, Y) [with X = long unsigned int, Y =
int]â:
helloWorld.cpp:16:   instantiated from here
helloWorld.cpp:7: warning: comparison between signed and unsigned integer
expressions


However if comparison is not inside a template say direct comparison:
if(x == y)

then g++-4.8.2 will pick this up as a warning:
bfs-dl360g7-27$ g++ --std=c++11 -Wall -Werror testComparison.cpp -o
testComparison
testComparison.cpp: In function âint main()â:
testComparison.cpp:9:12: error: comparison between signed and unsigned integer
expressions [-Werror=sign-compare]
if(x == y)

so it appears to have difficulty seeing this issue if wrapped in a
template/macro.


bfs-dl360g7-27$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/gcc-4.8.2/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.8.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --prefix=/opt/gcc-4.8.2 --enable-languages=c,c++
--with-mpc=/opt/gcc-4.8.2 --with-mpfr=/opt/gcc-4.8.2 --with-gmp=/opt/gcc-.8.2
--with-cloog=/opt/gcc-4.8.2 --with-isl=/opt/gcc-4.8.2
Thread model: posix
gcc version 4.8.2 (GCC)

preprocessed file attached -
apologies if i've missed anything vital or a bug already raised.
rgds

[Bug c++/59232] New: gcc misses [-Werror=sign-compare] when inside a template

2013-11-21 Thread a_mcgurn at yahoo dot co.uk
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59232

Bug ID: 59232
   Summary: gcc misses [-Werror=sign-compare] when inside a
template
   Product: gcc
   Version: 4.8.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: a_mcgurn at yahoo dot co.uk

The following code:

--- //filename 
#include 

template
bool equals( X x, Y y )
{
return (x == y);
}

int main()
{
   std::cout << "Hello World!" << std::endl;
   size_t x = 2;
   signed int y = 2;

   if(!equals( x, y ))
   {
  std::cout << "Hello World again - x == y !" << std::endl;
   }

   return 0;
}
---

This produces for g++-4.8.2:

bfs-dl360g7-27$ g++ --std=c++11 -Wall helloWorld.cpp -o helloWorld
NO warnings

for g++-4.4.7 it correctly warns on the 'signed == unsigned long' as incorrect:

bfs-dl360g7-27$ /usr/bin/g++ -Wall helloWorld.cpp -o helloWorld
helloWorld.cpp: In function âbool equals(X, Y) [with X = long unsigned int, Y =
int]â:
helloWorld.cpp:16:   instantiated from here
helloWorld.cpp:7: warning: comparison between signed and unsigned integer
expressions


However if comparison is not inside a template say direct comparison:
if(x == y)

then g++-4.8.2 will pick this up as a warning:
bfs-dl360g7-27$ g++ --std=c++11 -Wall -Werror testComparison.cpp -o
testComparison
testComparison.cpp: In function âint main()â:
testComparison.cpp:9:12: error: comparison between signed and unsigned integer
expressions [-Werror=sign-compare]
if(x == y)

so it appears to have difficulty seeing this issue if wrapped in a
template/macro.


bfs-dl360g7-27$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/gcc-4.8.2/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.8.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --prefix=/opt/gcc-4.8.2 --enable-languages=c,c++
--with-mpc=/opt/gcc-4.8.2 --with-mpfr=/opt/gcc-4.8.2 --with-gmp=/opt/gcc-.8.2
--with-cloog=/opt/gcc-4.8.2 --with-isl=/opt/gcc-4.8.2
Thread model: posix
gcc version 4.8.2 (GCC)

preprocessed file attached -
apologies if i've missed anything vital or a bug already raised.
rgds