Bug 83690 - [8 regression] spurious unused variable warings for variables used only in static_assert
Summary: [8 regression] spurious unused variable warings for variables used only in st...
Status: RESOLVED FIXED
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: diagnostic
Depends on:
Blocks:
 
Reported: 2018-01-04 18:48 UTC by scott snyder
Modified: 2018-01-11 19:11 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-01-05 00:00:00


Attachments
gcc8-pr83690.patch (787 bytes, patch)
2018-01-05 15:50 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description scott snyder 2018-01-04 18:48:31 UTC
As of 

gcc version 8.0.0 20180102 (experimental) (GCC) 

gcc gives an unused-but-set warning for variables that are used only in a 
static_assert.

For example, with this source:

--- x.cc -------------------------------------
void foo()
{
  constexpr bool foo = true;
  static_assert(foo, "foo");
}
----------------------------------------------

we get a warning:

$ cc1plus -std=c++17 x.cc -quiet -Wall
x.cc: In function ‘void foo()’:
x.cc:3:18: warning: variable ‘foo’ set but not used [-Wunused-but-set-variable]
   constexpr bool foo = true;
                  ^~~

We do not get this warning with gcc 7.2.1.
Comment 1 Jakub Jelinek 2018-01-05 15:35:19 UTC
Started with r253266.  Jason?
Comment 2 Jakub Jelinek 2018-01-05 15:50:48 UTC
Created attachment 43046 [details]
gcc8-pr83690.patch

This does seem to do the job.
Comment 3 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
Comment 4 Jason Merrill 2018-01-11 19:11:02 UTC
Fixed.