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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to