[LLVMbugs] [Bug 23416] New: false positive, unused loop variable
    bugzilla-daemon at llvm.org 
    bugzilla-daemon at llvm.org
       
    Tue May  5 10:01:37 PDT 2015
    
    
  
https://llvm.org/bugs/show_bug.cgi?id=23416
            Bug ID: 23416
           Summary: false positive, unused loop variable
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ncm at cantrip.org
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified
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: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.
-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150505/6dff8184/attachment.html>
    
    
More information about the llvm-bugs
mailing list