[Bug c++/56958] Spurious set but not used variable warning in empty pack expansion

2022-11-04 Thread serpent7776 at gmail dot com via Gcc-bugs
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

2022-02-01 Thread foom at fuhm dot net via Gcc-bugs
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

2018-06-21 Thread will at benfold dot com
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

2015-08-27 Thread ldionne.2 at gmail dot com
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_sequencei...) {
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_sequencei ...) [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.

[Bug c++/56958] Spurious set but not used variable warning in empty pack expansion

2013-04-27 Thread lucdanton at free dot fr


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

2013-04-26 Thread jakub at gcc dot gnu.org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56958



--- Comment #1 from Jakub Jelinek jakub at gcc dot gnu.org 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.


[Bug c++/56958] Spurious set but not used variable warning in empty pack expansion

2013-04-26 Thread paolo.carlini at oracle dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56958



--- Comment #2 from Paolo Carlini paolo.carlini at oracle dot com 2013-04-26 
14:30:29 UTC ---

I agree, looks like warning is fine...