public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66028] New: false positive, unused loop variable
@ 2015-05-05 20:19 ncm at cantrip dot org
  2015-05-06  7:52 ` [Bug c++/66028] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: ncm at cantrip dot org @ 2015-05-05 20:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 66028
           Summary: false positive, unused loop variable
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ncm at cantrip dot org
  Target Milestone: ---

struct range {
    int start; int stop;
    struct iter {
        int i;
        bool operator!=(iter other) { return other.i != i; };
        iter& operator++() { ++i; return *this; };
        int operator*() { return i; }
    };
    iter begin() { return iter{start}; }
    iter end() { return iter{stop}; }
};
int main()
{
   int power = 1;
   for (int i : range{0,10})
       power *= 10;
}
bug.cc: In function ‘int main()’:
bug.cc:15:13: warning: unused variable ‘i’ [-Wunused-variable]
    for (int i : range{0,10})

Manifestly, i is used to count loop iterations.  The warning cannot be
suppressed by any decoration of the declaration; the best we can do is

  void(i), power *= 10;

in the loop body.  The warning is useful in most cases.  The exception might be
that, here, the iterator has no reference or pointer members, and the loop body
changes external state.

[This matches clang bug https://llvm.org/bugs/show_bug.cgi?id=23416)
>From gcc-bugs-return-485573-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Tue May 05 20:33:52 2015
Return-Path: <gcc-bugs-return-485573-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 17675 invoked by alias); 5 May 2015 20:33:52 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 17643 invoked by uid 48); 5 May 2015 20:33:48 -0000
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/66018] opendir configure test not working when GCC_NO_EXECUTABLES
Date: Tue, 05 May 2015 20:33:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: libstdc++
X-Bugzilla-Version: unknown
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: redi at gcc dot gnu.org
X-Bugzilla-Status: ASSIGNED
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: redi at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status cf_reconfirmed_on assigned_to everconfirmed
Message-ID: <bug-66018-4-XVY8e1JhFf@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-66018-4@http.gcc.gnu.org/bugzilla/>
References: <bug-66018-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-05/txt/msg00413.txt.bz2
Content-length: 486

https://gcc.gnu.org/bugzilla/show_bug.cgi?idf018

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2015-05-05
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
     Ever confirmed|0                           |1


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

* [Bug c++/66028] false positive, unused loop variable
  2015-05-05 20:19 [Bug c++/66028] New: false positive, unused loop variable ncm at cantrip dot org
@ 2015-05-06  7:52 ` rguenth at gcc dot gnu.org
  2020-11-10 23:49 ` ncm at cantrip dot org
  2024-04-05 22:14 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-05-06  7:52 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-05-06
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.


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

* [Bug c++/66028] false positive, unused loop variable
  2015-05-05 20:19 [Bug c++/66028] New: false positive, unused loop variable ncm at cantrip dot org
  2015-05-06  7:52 ` [Bug c++/66028] " rguenth at gcc dot gnu.org
@ 2020-11-10 23:49 ` ncm at cantrip dot org
  2024-04-05 22:14 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: ncm at cantrip dot org @ 2020-11-10 23:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from ncm at cantrip dot org ---
This bug appears not to manifest in g++-10.2.

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

* [Bug c++/66028] false positive, unused loop variable
  2015-05-05 20:19 [Bug c++/66028] New: false positive, unused loop variable ncm at cantrip dot org
  2015-05-06  7:52 ` [Bug c++/66028] " rguenth at gcc dot gnu.org
  2020-11-10 23:49 ` ncm at cantrip dot org
@ 2024-04-05 22:14 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-05 22:14 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu.org

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to ncm from comment #2)
> This bug appears not to manifest in g++-10.2.

The warning is still there for me. Maybe you forgot to test with -Wall (or
-Wunused).

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

end of thread, other threads:[~2024-04-05 22:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-05 20:19 [Bug c++/66028] New: false positive, unused loop variable ncm at cantrip dot org
2015-05-06  7:52 ` [Bug c++/66028] " rguenth at gcc dot gnu.org
2020-11-10 23:49 ` ncm at cantrip dot org
2024-04-05 22:14 ` pinskia at gcc dot gnu.org

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).