public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/62243] New: Non-typename template argument behaviour in loop (unsigned int)
@ 2014-08-24  8:03 bjodah at gmail dot com
  2014-08-24  8:28 ` [Bug c++/62243] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: bjodah at gmail dot com @ 2014-08-24  8:03 UTC (permalink / raw)
  To: gcc-bugs

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?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/62243] Non-typename template argument behaviour in loop (unsigned int)
  2014-08-24  8:03 [Bug c++/62243] New: Non-typename template argument behaviour in loop (unsigned int) bjodah at gmail dot com
@ 2014-08-24  8:28 ` pinskia at gcc dot gnu.org
  2014-08-24  8:31 ` glisse at gcc dot gnu.org
  2014-08-24  8:32 ` bjodah at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-08-24  8:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62243

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
i <= w if I and w are int then the compare is done in int but if w is unsigned
int, then it is done in unsigned int so (unsigned int)-3 is always greater than
3.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/62243] Non-typename template argument behaviour in loop (unsigned int)
  2014-08-24  8:03 [Bug c++/62243] New: Non-typename template argument behaviour in loop (unsigned int) bjodah at gmail dot com
  2014-08-24  8:28 ` [Bug c++/62243] " pinskia at gcc dot gnu.org
@ 2014-08-24  8:31 ` glisse at gcc dot gnu.org
  2014-08-24  8:32 ` bjodah at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: glisse at gcc dot gnu.org @ 2014-08-24  8:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62243

--- Comment #2 from Marc Glisse <glisse at gcc dot gnu.org> ---
Please always compile your programs with -Wall, it would have told you what was
wrong.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/62243] Non-typename template argument behaviour in loop (unsigned int)
  2014-08-24  8:03 [Bug c++/62243] New: Non-typename template argument behaviour in loop (unsigned int) bjodah at gmail dot com
  2014-08-24  8:28 ` [Bug c++/62243] " pinskia at gcc dot gnu.org
  2014-08-24  8:31 ` glisse at gcc dot gnu.org
@ 2014-08-24  8:32 ` bjodah at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: bjodah at gmail dot com @ 2014-08-24  8:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62243

--- Comment #3 from Bjoern Dahlgren <bjodah at gmail dot com> ---
Will do. Sorry for this and thank you.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-08-24  8:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-24  8:03 [Bug c++/62243] New: Non-typename template argument behaviour in loop (unsigned int) bjodah at gmail dot com
2014-08-24  8:28 ` [Bug c++/62243] " pinskia at gcc dot gnu.org
2014-08-24  8:31 ` glisse at gcc dot gnu.org
2014-08-24  8:32 ` bjodah at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).