[Bug c++/56958] Spurious set but not used variable warning in empty pack expansion
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56958 serpent7776 at gmail dot com changed: What|Removed |Added CC||serpent7776 at gmail dot com --- Comment #7 from serpent7776 at gmail dot com --- I was just hit by this warning in a very similar scenario. To me this warning in this context is not only unhelpful, but confusing. clang doesn't issue this warning in this context.
[Bug c++/56958] Spurious set but not used variable warning in empty pack expansion
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56958 James Y Knight changed: What|Removed |Added CC||foom at fuhm dot net --- Comment #6 from James Y Knight --- I agree with the other people noting that it isn't _useful_ to warn about this construct, and that this ought to be considered a valid bug, not working as intended.
[Bug c++/56958] Spurious set but not used variable warning in empty pack expansion
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56958 Will Benfold changed: What|Removed |Added CC||will at benfold dot com --- Comment #5 from Will Benfold --- Still present in 7.3.0: $ cat test.cpp template int foo (int n) { return (( (n) + Is ) + ... + 0); } int main (int, char *[]) { foo<1>(0); foo<>(0); return 0; } $ g++ -std=c++17 -Wall -Wextra -o test test.cpp test.cpp: In instantiation of ‘int foo(int) [with int ...Is = {}]’: test.cpp:10:10: required from here test.cpp:2:14: warning: parameter ‘n’ set but not used [-Wunused-but-set-parameter] int foo (int n) The warning goes away if the parentheses are removed from (n), or if it's changed to (n+0).
[Bug c++/56958] Spurious set but not used variable warning in empty pack expansion
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56958 Louis Dionne changed: What|Removed |Added CC||ldionne.2 at gmail dot com --- Comment #4 from Louis Dionne --- The following code triggers the same warning on GCC trunk: -- struct Object { int method(int) const { return 0; } }; template void expand(T&&...); template struct index_sequence { }; template struct TemplateStruct { static constexpr Object get_object() { return {}; } template static void f(index_sequence) { 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< >::f(index_sequence) [with int ...i = {}; = {}]’: [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.
[Bug c++/56958] Spurious set but not used variable warning in empty pack expansion
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56958 --- Comment #3 from lucdanton at free dot fr 2013-04-28 00:37:37 UTC --- I do make use of the variable in the pack; that the pack may be empty for some instantiations may or may not be something to look out for, but I don't think that it should be done by the unused variable warning. Perhaps I misunderstand the role of warning -- to me the 'used' in 'unused variable' means that it's conceptually used, not that it's e.g. ODR-used or any technical sense of the term. Should the following code warn? Who does that benefit? int spurious = 0 if(1) return 0; // never reached -- is spurious used or not? return spurious + 3; Since GCC doesn't warn for this I thought it shouldn't in the case of the pack expansion.
[Bug c++/56958] Spurious set but not used variable warning in empty pack expansion
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56958 --- Comment #2 from Paolo Carlini 2013-04-26 14:30:29 UTC --- I agree, looks like warning is fine...
[Bug c++/56958] Spurious set but not used variable warning in empty pack expansion
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56958 --- Comment #1 from Jakub Jelinek 2013-04-26 14:23:27 UTC --- Well, you aren't using spurious, are you? Because t + spurious... expands to nothing. If mark_exp_read isn't called while processing_template_decl because the expression is type dependent, and during instantiation is lost altogether, not sure where could we call mark_rvalue_use etc.