https://bugs.llvm.org/show_bug.cgi?id=36627

            Bug ID: 36627
           Summary: clang emits extraneous -Wunused-variable for RAII
                    const reference variable
           Product: clang
           Version: 5.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: anntzer....@gmail.com
                CC: llvm-bugs@lists.llvm.org

Consider

    struct S {
        S();
        ~S();  // Assume this actually does some RAII cleanup.
    };

    extern int f();

    int main() {
        auto const t = S();  // No warning.
        auto const& u = S();  // "warning: unused variable 'u'
[-Wunused-variable]".
        f();  // Just so that clang has no way to know whether some work will
be done here.
    }

and compile (e.g.) with `--std=c++17 -Wall -Wextra -Wpedantic`

clang (5.0.1 Arch Linux package) correctly recognizes that `t` could be
involved in RAII, but emits an unused-variable warning about `u` even though it
can also participate in RAII in the same way (as the lifetime of the const
reference is prolonged until the end of the scope).  [Note that it would be a
different issue if clang neither recognized the possibility of RAII happening
for either `t` or `u`.]

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to