This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/62243] New: Non-typename template argument behaviour in loop (unsigned int)
- From: "bjodah at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 24 Aug 2014 08:03:10 +0000
- Subject: [Bug c++/62243] New: Non-typename template argument behaviour in loop (unsigned int)
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62243
Bug ID: 62243
Summary: Non-typename template argument behaviour in loop
(unsigned int)
Product: gcc
Version: 4.8.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: bjodah at gmail dot com
I have come across something that puzzles me quite a bit, consider this small
program:
#include <iostream>
template <int w>
void f(){
for (int i=-1*static_cast<int>(w); i <= w; ++i)
std::cout << i << std::endl;
}
int main()
{
f<3>();
return 0;
}
which generates as expected output -3 to 2.
However changing the type of the non-type template argument to unsigned int,
i.e. `template <unsigned int w>` makes the program skip the loop. (g++ 4.8.2 &
clang++ 3.4)
Is this a bug in the compiler or is it the expected behaviour?