[Bug c++/82800] New: Incorrect warning on "may be used uninitialized in this function" in variadic template code
alonzakai at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Nov 1 23:06:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82800
Bug ID: 82800
Summary: Incorrect warning on "may be used uninitialized in
this function" in variadic template code
Product: gcc
Version: 7.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: alonzakai at gmail dot com
Target Milestone: ---
The testcase below fails with
g++- a.cpp -std=c++11 -Wall -Werror -O2
It fails on 7.2.0, but works on 5.4.0, so this looks like a regression.
Testcase:
===
#include <cmath>
#include <cstdint>
#include <cstdlib>
struct Maker {
double makeConst() {
return pick<double>(0, 0, 0, 0, 0, 0, 1);
}
template<typename T, typename... Args>
T pick(T first, Args... args) {
return pickGivenNum<T>(rand(), first, args...);
}
template<typename T>
T pickGivenNum(size_t num, T first) {
if (num != 0) abort();
return first;
}
template<typename T, typename... Args>
T pickGivenNum(size_t num, T first, Args... args) {
if (num == 0) return first;
return pickGivenNum<T>(num - 1, args...);
}
};
int main() {
Maker maker;
maker.makeConst();
maker.makeConst();
}
===
The error is
===
a.cpp: In function ‘double Maker::makeConst()’:
a.cpp:8:44: error: ‘first’ may be used uninitialized in this function
[-Werror=maybe-uninitialized]
return pick<double>(0, 0, 0, 0, 0, 0, 1);
^
===
This may have something to do with it being a variadic template (I couldn't
reduce it any more without that template).
More information about the Gcc-bugs
mailing list