Bug 66543 - False positive warning "variable set but not used"
Summary: False positive warning "variable set but not used"
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: 6.0
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-15 13:34 UTC by Louis Dionne
Modified: 2016-04-22 14:59 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-06-18 00:00:00


Attachments
patch for after gcc 6 (1.41 KB, patch)
2016-03-04 23:25 UTC, Jason Merrill
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Louis Dionne 2015-06-15 13:34:03 UTC
The following code triggers a "unused but set variable" warning on GCC trunk:

    int main() {
        auto f = []() { };
        [=](auto) {
            using Foo = decltype(f());
        };
    }

I think it is a false positive, since `f` is obviously used.

> g++ --version
g++ (GCC) 6.0.0 20150613 (experimental)

> g++ -std=c++14 worksheet.cpp -fsyntax-only -Wall -Wno-unused-local-typedefs

In function ‘int main()’:
warning: variable ‘f’ set but not used [-Wunused-but-set-variable]
         auto f = []() { };
              ^

Regards,
Louis Dionne
Comment 1 Marek Polacek 2015-06-18 08:54:18 UTC
Confirmed.
Comment 2 Jason Merrill 2016-03-04 23:25:37 UTC
Created attachment 37873 [details]
patch for after gcc 6
Comment 3 Jason Merrill 2016-04-19 19:30:54 UTC
Author: jason
Date: Tue Apr 19 19:30:22 2016
New Revision: 235221

URL: https://gcc.gnu.org/viewcvs?rev=235221&root=gcc&view=rev
Log:
	PR c++/66543 - -Wunused-but-set* false positives

	* expr.c (mark_exp_read): Handle NON_DEPENDENT_EXPR.
	* pt.c (make_pack_expansion): Call mark_exp_read.
	* semantics.c (finish_id_expression): Call mark_type_use in
	unevaluated context.

Added:
    trunk/gcc/testsuite/g++.dg/warn/Wunused-parm-7.C
    trunk/gcc/testsuite/g++.dg/warn/Wunused-parm-8.C
    trunk/gcc/testsuite/g++.dg/warn/Wunused-var-24.C
    trunk/gcc/testsuite/g++.dg/warn/Wunused-var-25.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/expr.c
    trunk/gcc/cp/pt.c
    trunk/gcc/cp/semantics.c
Comment 4 Jason Merrill 2016-04-20 13:24:49 UTC
Author: jason
Date: Wed Apr 20 13:24:17 2016
New Revision: 235279

URL: https://gcc.gnu.org/viewcvs?rev=235279&root=gcc&view=rev
Log:
	PR c++/66543 - -Wunused-but-set* false positives

	* expr.c (mark_exp_read): Handle NON_DEPENDENT_EXPR.
	* pt.c (make_pack_expansion): Call mark_exp_read.
	* semantics.c (finish_id_expression): Call mark_type_use in
	unevaluated context.

Added:
    branches/gcc-6-branch/gcc/testsuite/g++.dg/warn/Wunused-parm-7.C
    branches/gcc-6-branch/gcc/testsuite/g++.dg/warn/Wunused-parm-8.C
    branches/gcc-6-branch/gcc/testsuite/g++.dg/warn/Wunused-var-24.C
    branches/gcc-6-branch/gcc/testsuite/g++.dg/warn/Wunused-var-25.C
Modified:
    branches/gcc-6-branch/gcc/cp/ChangeLog
    branches/gcc-6-branch/gcc/cp/expr.c
    branches/gcc-6-branch/gcc/cp/pt.c
    branches/gcc-6-branch/gcc/cp/semantics.c
Comment 5 Jason Merrill 2016-04-22 14:59:17 UTC
Fixed for GCC 6.