Bug 82799 - [8 Regression] -Wunused-but-set-variable false positive
Summary: [8 Regression] -Wunused-but-set-variable false positive
Status: RESOLVED DUPLICATE of bug 82728
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-01 22:38 UTC by Steinar H. Gunderson
Modified: 2018-01-11 19:09 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-11-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steinar H. Gunderson 2017-11-01 22:38:57 UTC
Hi,

Reduced testcase (automatically; it might be possible to reduce further):

enum a { b };     
struct c {
	template < a > int d() {
		const bool is_ident = 0;
		const int ret = is_ident ? 7 : 9;
		return ret;
	}
        void e() {
		d < b > ();
	}
};

When compiled with -Wall, yields:

test.cc: In instantiation of 'int c::d() [with a <anonymous> = (a)0]':
test.cc:9:12:   required from here
test.cc:4:14: warning: variable 'is_ident' set but not used [-Wunused-but-set-variable]
   const bool is_ident = 0;
              ^~~~~~~~

even though is_ident is clearly used on the line below.

gcc version 8.0.0 20171017 (experimental) [trunk revision 253812] (Debian 20171017-1) 

This does not happen with GCC 7.2.1.
Comment 1 Jakub Jelinek 2017-11-16 18:00:34 UTC
Started with r253266.
Comment 2 Markus Trippelsdorf 2017-12-04 10:39:52 UTC
Looks like a dup of PR82728.
Comment 3 Jakub Jelinek 2017-12-04 11:07:03 UTC
Indeed, let's do it, but make sure we have both testcases in the testsuite after the fix.

*** This bug has been marked as a duplicate of bug 82728 ***
Comment 4 Jason Merrill 2018-01-11 19:09:14 UTC
Author: jason
Date: Thu Jan 11 19:08:41 2018
New Revision: 256550

URL: https://gcc.gnu.org/viewcvs?rev=256550&root=gcc&view=rev
Log:
	PR c++/82728 - wrong -Wunused-but-set-variable

	PR c++/82799
	PR c++/83690
	* call.c (perform_implicit_conversion_flags): Call mark_rvalue_use.
	* decl.c (case_conversion): Likewise.
	* semantics.c (finish_static_assert): Call
	perform_implicit_conversion_flags.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-switch2.C
    trunk/gcc/testsuite/g++.dg/warn/Wunused-var-27.C
    trunk/gcc/testsuite/g++.dg/warn/Wunused-var-28.C
    trunk/gcc/testsuite/g++.dg/warn/Wunused-var-29.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/semantics.c