https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101901
Bug ID: 101901
Summary: "warning: statement has no effect" in a variadic
template with empty parameter pack.
Product: gcc
Version: 11.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: officesamurai at gmail dot com
Target Milestone: ---
gcc_statement_has_no_effect.cpp:
---
#include <string>
template <typename T>
void foo(const T*, int);
template <typename T>
std::string bar(T);
template <typename... T>
void callFoo(T... t)
{
const std::string array[] = {bar(t)...};
foo(array, sizeof...(t));
}
void test()
{
callFoo();
}
---
Compiler invocation:
---
$ g++-11.2.0 -c gcc_statement_has_no_effect.cpp -Wunused-value
gcc_statement_has_no_effect.cpp: In instantiation of ‘void callFoo(T ...) [with
T = {}]’:
gcc_statement_has_no_effect.cpp:18:12: required from here
gcc_statement_has_no_effect.cpp:12:23: warning: statement has no effect
[-Wunused-value]
12 | const std::string array[] = {bar(t)...};
| ^~~~~
---
Technically, the compiler is correct of course, but the warning is rather
annoying, because it forces the programmer to explicitly handle this specific
case.
Also, GCC 10.3.0 doesn't produce the warning in this case.
Compiler version:
---
$ g++-11.2.0 -v
Using built-in specs.
COLLECT_GCC=g++-11.2.0
COLLECT_LTO_WRAPPER=/home/brd/soft/gcc-11.2.0/libexec/gcc/x86_64-pc-linux-gnu/11.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/home/brd/soft/gcc-11.2.0
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC)
---