Bug 82728 - [8 regression] Incorrect -Wunused-but-set-variable warning with a const
Summary: [8 regression] Incorrect -Wunused-but-set-variable warning with a const
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0
: P1 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
: 82799 (view as bug list)
Depends on: 85963
Blocks:
  Show dependency treegraph
 
Reported: 2017-10-26 07:24 UTC by Sylvestre Ledru
Modified: 2018-06-11 07:49 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-12-04 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sylvestre Ledru 2017-10-26 07:24:03 UTC
with:

void foo(void) {
  const int ID = 1;
  switch (0) {
  case ID:
    break;
  }
}

# gcc-7 -Wall -c foo.cpp 
# gcc-8 -Wall -c foo.cpp 
foo.cpp: In function 'void foo()':
foo.cpp:2:13: warning: variable 'ID' set but not used [-Wunused-but-set-variable]
   const int ID = 1;
             ^~
Comment 1 Markus Trippelsdorf 2017-12-04 10:36:51 UTC
Started with r253266:

commit 4cedc476c94a41551d965bc57fbbe0186983c3c4
Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Thu Sep 28 19:39:45 2017 +0000

            PR c++/56973, DR 696 - capture constant variables only as needed.
Comment 2 Jakub Jelinek 2017-12-04 11:06:24 UTC
Testcase from another PR for similar issue:
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 > ();
	}
};
Comment 3 Jakub Jelinek 2017-12-04 11:07:04 UTC
*** Bug 82799 has been marked as a duplicate of this bug. ***
Comment 4 Jason Merrill 2018-01-11 19:09:13 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
Comment 5 Jason Merrill 2018-01-11 19:10:34 UTC
Fixed.
Comment 6 Michael Cortez 2018-05-29 04:30:45 UTC
(In reply to Jason Merrill from comment #5)
> Fixed.

It seems to be broken again on gcc 8.1:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85963