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


    struct 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'
        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

Reply via email to