https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56958
Louis Dionne <ldionne.2 at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ldionne.2 at gmail dot com --- Comment #4 from Louis Dionne <ldionne.2 at gmail dot com> --- The following code triggers the same warning on GCC trunk: ------------------------------------------------------------------------------ struct Object { int method(int) const { return 0; } }; template <typename ...T> void expand(T&&...); template <int ...> struct index_sequence { }; template <typename ...> struct TemplateStruct { static constexpr Object get_object() { return {}; } template <int ...i> static void f(index_sequence<i...>) { constexpr auto object = get_object(); // only fires with 'auto' expand(object.method(i)...); } }; template void TemplateStruct<>::f(index_sequence<>); ------------------------------------------------------------------------------ The warning is: [snip]: In instantiation of ‘ static void TemplateStruct< <template-parameter-1-1> >::f(index_sequence<i ...>) [with int ...i = {}; <template-parameter-1-1> = {}]’: [snip]: required from here [snip]: warning: variable ‘object’ set but not used [-Wunused-but-set-variable] constexpr auto object = get_object(); // only fires with 'auto' ^ This is very annoying because that will cause perfectly fine code to emit warnings when used with empty parameter packs. Also surprising is that the warning goes away if either (1) A non-template struct is used instead of TemplateStruct (2) One uses `Object object = ...` instead of `auto object = ...` which makes it obvious that this is a bug, not a feature. Please fix your compiler, or metaprogrammers all around the world will hate you for forcing them to write constexpr auto object = get_object(); (void)object; // workaround GCC false positive expand(object.method(i)...); in every place where a variable may be 'unused' when a parameter pack is empty.