[llvm-bugs] [Bug 50533] New: Wunused-const-variable warns when variable template is used in body of uninstantiated function template

via llvm-bugs llvm-bugs at lists.llvm.org
Sun May 30 10:59:50 PDT 2021


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

            Bug ID: 50533
           Summary: Wunused-const-variable warns when variable template is
                    used in body of uninstantiated function template
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: davidfromonline at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

The following translation unit

```
namespace {

template<typename T>
constexpr bool false_ = false;

}

template<typename T>
void f() {
        static_assert(false_<T>);
}
```

warns when compiled with `-Wunused-const-variable`:

```
<source>:4:16: warning: unused variable 'false_' [-Wunused-const-variable]
constexpr bool false_ = false;
               ^
1 warning generated.
Compiler returned: 0
```

even though the variable is clearly used.

See it live: https://godbolt.org/z/oYxMq1K6r

If an instantiation of `f` is visible, the warning goes away, but not all
instantiations are necessarily visible. The warning is also triggered with the
following slightly larger translation unit:

```
namespace {

template<typename T>
constexpr bool false_ = false;

}

template<typename T>
void f() {
        static_assert(false_<T>);
}

template<typename T>
concept c = requires { f<T>(); };

static_assert(c<int>);
```

See it live: https://godbolt.org/z/f74G5Tx54

-- 
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/20210530/30185ac4/attachment.html>


More information about the llvm-bugs mailing list