[Bug c++/85963] New: false positive "set but not used" warning [-Wunused-but-set-variable]
mcortez at airpost dot net
gcc-bugzilla@gcc.gnu.org
Tue May 29 04:28:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85963
Bug ID: 85963
Summary: false positive "set but not used" warning
[-Wunused-but-set-variable]
Product: gcc
Version: 8.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mcortez at airpost dot net
Target Milestone: ---
Related to, but not fixed by:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82728
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82799
Getting an annoying false positive "set but not used" warning when compiling
with -Wall
g++ (GCC) 8.1.1 20180502 (Red Hat 8.1.1-1) on Fedora 28. gcc was updated to
whatever the latest version is available in Fedora 28 update repos.
Reduced test case:
template<typename T>
struct foo {
T val, alpha;
foo() : val(0), alpha(0) {}
};
template<typename T>
inline void bar(const foo<T>& A, const foo<T>& B, foo<T>& C) {
const bool use_alpha = true;
const T alpha = use_alpha ? (A.alpha * B.alpha) : T(0);
C.val = A.val * B.val;
C.alpha = alpha;
}
int main() {
foo<double> A,B,C;
bar(A,B,C);
return 0;
}
g++ gccwarn.cpp -o gccwarn -Wall -O2
gccwarn.cpp: In instantiation of ‘void bar(const foo<T>&, const foo<T>&,
foo<T>&) [with T = double]’:
gccwarn.cpp:21:12: required from here
gccwarn.cpp:10:14: warning: variable ‘use_alpha’ set but not used
[-Wunused-but-set-variable]
const bool use_alpha = true;
^~~~~~~~~
More information about the Gcc-bugs
mailing list