public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/44811]  New: non controlable bogus warning: right/left shift count is negative
@ 2010-07-04 14:54 gpiez at web dot de
  2010-07-04 15:03 ` [Bug c++/44811] " rguenth at gcc dot gnu dot org
  2010-07-05  1:14 ` [Bug c++/44811] non controllable " pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 6+ messages in thread
From: gpiez at web dot de @ 2010-07-04 14:54 UTC (permalink / raw)
  To: gcc-bugs

template<int N>
uint64_t shift(uint64_t b) {
    if (N > 0)
        return b << N;
    else
        return b >> -N;
}

int main() {
    int a = shift<-5>(0x100);
    int b = shift<5>(0x100);
    return a+b;
}

---
I am using this function template in a header, and other warnings and even
errors tend to get cluttered by the output of bogus "shift count is negative"
warnings. I understand that dead code elimination happens only in the optimizer
and probably to late to see that the negative shift count branch is never
executed, and I could live with that if the warning was controlable with some
"-W" option. Alas, it seems, it is not.
The only way to supress this warning is using "-w", which also inhibits other,
potential useful warnings, so using "-w" everywhere is not really an option.


-- 
           Summary: non controlable bogus warning: right/left shift count is
                    negative
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gpiez at web dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44811


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

* [Bug c++/44811] non controlable bogus warning: right/left shift count is negative
  2010-07-04 14:54 [Bug c++/44811] New: non controlable bogus warning: right/left shift count is negative gpiez at web dot de
@ 2010-07-04 15:03 ` rguenth at gcc dot gnu dot org
  2010-07-05  1:14 ` [Bug c++/44811] non controllable " pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-07-04 15:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2010-07-04 15:02 -------
Confirmed.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |diagnostic
   Last reconfirmed|0000-00-00 00:00:00         |2010-07-04 15:02:52
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44811


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

* [Bug c++/44811] non controllable bogus warning: right/left shift count is negative
  2010-07-04 14:54 [Bug c++/44811] New: non controlable bogus warning: right/left shift count is negative gpiez at web dot de
  2010-07-04 15:03 ` [Bug c++/44811] " rguenth at gcc dot gnu dot org
@ 2010-07-05  1:14 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-07-05  1:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2010-07-05 01:14 -------
Related to PR 11856.  


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44811


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

* [Bug c++/44811] non controllable bogus warning: right/left shift count is negative
       [not found] <bug-44811-4@http.gcc.gnu.org/bugzilla/>
  2012-04-12 21:37 ` drwowe at yahoo dot com
  2012-04-26 18:03 ` dpiepgrass at mentoreng dot com
@ 2013-06-06 21:39 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-06-06 21:39 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44811

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|gcc-bugs at gcc dot gnu.org        |
         Resolution|---                         |DUPLICATE

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
This is a Dup of PR11856. Comment #3 is different, I think it's a known kind of
issue anyway.

*** This bug has been marked as a duplicate of bug 11856 ***


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

* [Bug c++/44811] non controllable bogus warning: right/left shift count is negative
       [not found] <bug-44811-4@http.gcc.gnu.org/bugzilla/>
  2012-04-12 21:37 ` drwowe at yahoo dot com
@ 2012-04-26 18:03 ` dpiepgrass at mentoreng dot com
  2013-06-06 21:39 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 6+ messages in thread
From: dpiepgrass at mentoreng dot com @ 2012-04-26 18:03 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44811

David Piepgrass <dpiepgrass at mentoreng dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dpiepgrass at mentoreng dot
                   |                            |com

--- Comment #4 from David Piepgrass <dpiepgrass at mentoreng dot com> 2012-04-26 18:02:34 UTC ---
What makes warnings like this really irritating is that templates get
instantiated more than once. I'm getting about two dozen of these warnings from
just two lines of template code, since the template is instantiated for many
integer values. And that's just from one cpp file; other cpp files give a
separate set of warnings (I'd consider using extern template, except that I
have to target MSVC9 too.)

Actually, GCC currently gives many thousand warnings for my project: it seems
nearly half of them come from these left/right shift warnings, and nearly half
also come from a couple dozen member functions of the form "Foo Foo() const {
... }" that my code contains, which never bothered MSVC.

The documentation of the diagnostic pragma
(http://gcc.gnu.org/onlinedocs/gcc-4.6.0/gcc/Diagnostic-Pragmas.html) doesn't
say how to disable all warnings... should this work?

    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-w"
    template<int N> uint64_t shift(uint64_t b) {
        if (N > 0)
            return b << N;
        else
            return b >> -N;
    }
    #pragma GCC diagnostic pop

It doesn't work for me, but it may just be my older GCC (4.4.3 for Google
Android). 4.4.3 complains about not supporting push/pop, but it doesn't
complain about -w even though it does not actually suppress any warnings.

Could I perhaps disable all warnings by default, and then use a pragma to
re-enable all warnings when the .cpp is reached?


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

* [Bug c++/44811] non controllable bogus warning: right/left shift count is negative
       [not found] <bug-44811-4@http.gcc.gnu.org/bugzilla/>
@ 2012-04-12 21:37 ` drwowe at yahoo dot com
  2012-04-26 18:03 ` dpiepgrass at mentoreng dot com
  2013-06-06 21:39 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 6+ messages in thread
From: drwowe at yahoo dot com @ 2012-04-12 21:37 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44811

D W <drwowe at yahoo dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |drwowe at yahoo dot com

--- Comment #3 from D W <drwowe at yahoo dot com> 2012-04-12 21:36:14 UTC ---
I'm also getting a different but similar warning.

Trivial example:

int shiftifbig(int x) {
  if (sizeof(x) > 4) {
    return x>>32;
  } else {
    return x;
  }
}

produces the following spurious warning:

warning: right shift count >= width of type [enabled by default]


Please gate this warning on something like -Wshift so that the corresponding
-Wno-shift could be used.
Even better, suppress the warning automatically from dead code like in the
above example.


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

end of thread, other threads:[~2013-06-06 21:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-04 14:54 [Bug c++/44811] New: non controlable bogus warning: right/left shift count is negative gpiez at web dot de
2010-07-04 15:03 ` [Bug c++/44811] " rguenth at gcc dot gnu dot org
2010-07-05  1:14 ` [Bug c++/44811] non controllable " pinskia at gcc dot gnu dot org
     [not found] <bug-44811-4@http.gcc.gnu.org/bugzilla/>
2012-04-12 21:37 ` drwowe at yahoo dot com
2012-04-26 18:03 ` dpiepgrass at mentoreng dot com
2013-06-06 21:39 ` paolo.carlini at oracle 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).