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

            Bug ID: 46035
           Summary: False-positive: -Wunused-variable warning triggers for
                    non-instantiated class-template specialization
           Product: clang
           Version: 10.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangb...@nondot.org
          Reporter: jba...@gmail.com
                CC: llvm-bugs@lists.llvm.org, neeil...@live.com,
                    richard-l...@metafoo.co.uk

Small repro via CRTP:
```
template <typename T, bool B>
struct Base {
    void foo() {
        // no-op
    }
};

template <typename T>
struct Base<T, true> {
    void foo() {
        size_t var = 1; // <--- LoC for which the warning is issued for
    }
};

template <bool B>
struct Derived : public Base<Derived<B>, B> {
    void bar() {
        this->foo();
    }
};

Derived<false> d;
```
Compiling this code-excerpt with `clang++ -std=c++11 -Wall` results with
false-positive warning:
```
warning: unused variable 'var' [-Wunused-variable]
        size_t var = 1;
```

I've checked other combos like {C++11, C++14, C++17, C++2a} x {clang-6,
clang-7, clang-8, ... clang-trunk} and warning is still there.

Mind that one does not have to `Derived<false> d;` to get a warning (it's in
the example for clarity reasons) and in real-world scenario `size_t var = ...`
is being used in the very next line (in production-code).

Thanks,
Adi
Mind

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

Reply via email to