This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/81299] New: Spurious "set but not used" warning with constexpr variable
- From: "ldionne.2 at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 04 Jul 2017 01:45:20 +0000
- Subject: [Bug c++/81299] New: Spurious "set but not used" warning with constexpr variable
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81299
Bug ID: 81299
Summary: Spurious "set but not used" warning with constexpr
variable
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ldionne.2 at gmail dot com
Target Milestone: ---
The following code triggers a spurious warning on GCC trunk (8.0 ish):
struct function_t {
template <typename ...Xs>
void operator()(Xs&& ...) const { }
};
constexpr function_t function{};
int main() {
constexpr auto fun = ::function;
auto call = [=](auto ...x) { fun(x...); };
call();
}
The output is:
prog.cc: In function 'int main()':
prog.cc:8:20: warning: variable 'fun' set but not used
[-Wunused-but-set-variable]
constexpr auto fun = ::function;
^~~
Live example: https://godbolt.org/g/jNhNJV
This is an incredibly annoying bug that was also present in GCC 7 and causes
trivial constexpr code to fail to compile (when -Werror is used) :-(.
Sorry for using Godbolt (which does not clearly show the warning message)
instead of Wandbox, but Wandbox's shareable links feature are not working right
now.