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?

Reply via email to