public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96311] New: false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda)
@ 2020-07-24 15:36 tilkax at gmail dot com
2020-07-27 7:11 ` [Bug c++/96311] " marxin at gcc dot gnu.org
` (13 more replies)
0 siblings, 14 replies; 15+ messages in thread
From: tilkax at gmail dot com @ 2020-07-24 15:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96311
Bug ID: 96311
Summary: false positive for -Wunused-but-set-variable
(const/constexpr identifier used in generic lambda)
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: tilkax at gmail dot com
Target Milestone: ---
Using gcc version 11.0.0 20200723, this code:
void foo()
{
constexpr int used = 0;
[](auto unused)
{
return used;
};
}
triggers an incorrect warning:
<source>:3:19: warning: variable 'used' set but not used
[-Wunused-but-set-variable]
3 | constexpr int used = 0;
| ^~~~
It doesn't matter whether the lambda is called but it does need to be a generic
lambda to trigger the incorrect warning.
Also, both the lambda parameter as well as the lambda itself are unused here
but don't trigger any warnings :/
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/96311] false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda)
2020-07-24 15:36 [Bug c++/96311] New: false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda) tilkax at gmail dot com
@ 2020-07-27 7:11 ` marxin at gcc dot gnu.org
2020-07-27 7:40 ` tilkax at gmail dot com
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-07-27 7:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96311
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
CC| |marxin at gcc dot gnu.org
Last reconfirmed| |2020-07-27
Status|UNCONFIRMED |WAITING
--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Confirmed, but it seems the code is rejected with clang:
pr96311.c:6:10: error: variable 'used' cannot be implicitly captured in a
lambda with no capture-default specified
return used;
^
pr96311.c:3:16: note: 'used' declared here
constexpr int used = 0;
^
pr96311.c:4:2: note: lambda expression begins here
[](auto unused)
^
pr96311.c:4:2: warning: expression result unused [-Wunused-value]
[](auto unused)
^~~~~~~~~~~~~~~
2 warnings and 1 error generated.
Is it a valid test-case?
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/96311] false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda)
2020-07-24 15:36 [Bug c++/96311] New: false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda) tilkax at gmail dot com
2020-07-27 7:11 ` [Bug c++/96311] " marxin at gcc dot gnu.org
@ 2020-07-27 7:40 ` tilkax at gmail dot com
2020-07-27 10:09 ` [Bug c++/96311] [8/9/10/11 Regression] " jakub at gcc dot gnu.org
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: tilkax at gmail dot com @ 2020-07-27 7:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96311
--- Comment #2 from Tillmann Karras <tilkax at gmail dot com> ---
(In reply to Martin Liška from comment #1)
> Confirmed, but it seems the code is rejected with clang:
> [...]
> Is it a valid test-case?
I think so.
There is a bug report for Clang: https://bugs.llvm.org/show_bug.cgi?id=25627
And MSVC used to have the same problem:
https://developercommunity.visualstudio.com/content/problem/367326/problems-with-capturing-constexpr-in-lambda.html
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/96311] [8/9/10/11 Regression] false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda)
2020-07-24 15:36 [Bug c++/96311] New: false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda) tilkax at gmail dot com
2020-07-27 7:11 ` [Bug c++/96311] " marxin at gcc dot gnu.org
2020-07-27 7:40 ` tilkax at gmail dot com
@ 2020-07-27 10:09 ` jakub at gcc dot gnu.org
2020-07-27 10:17 ` jakub at gcc dot gnu.org
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-07-27 10:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96311
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |NEW
Summary|false positive for |[8/9/10/11 Regression]
|-Wunused-but-set-variable |false positive for
|(const/constexpr identifier |-Wunused-but-set-variable
|used in generic lambda) |(const/constexpr identifier
| |used in generic lambda)
Target Milestone|--- |8.5
CC| |jakub at gcc dot gnu.org
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Started with r8-3497-g281e6c1d8f1b4ca552d8ce2276ddecfcd6ffb15e
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/96311] [8/9/10/11 Regression] false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda)
2020-07-24 15:36 [Bug c++/96311] New: false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda) tilkax at gmail dot com
` (2 preceding siblings ...)
2020-07-27 10:09 ` [Bug c++/96311] [8/9/10/11 Regression] " jakub at gcc dot gnu.org
@ 2020-07-27 10:17 ` jakub at gcc dot gnu.org
2021-02-11 15:25 ` jakub at gcc dot gnu.org
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-07-27 10:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96311
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
CC| |jason at gcc dot gnu.org
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/96311] [8/9/10/11 Regression] false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda)
2020-07-24 15:36 [Bug c++/96311] New: false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda) tilkax at gmail dot com
` (3 preceding siblings ...)
2020-07-27 10:17 ` jakub at gcc dot gnu.org
@ 2021-02-11 15:25 ` jakub at gcc dot gnu.org
2021-03-10 17:29 ` hewillk at gmail dot com
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-02-11 15:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96311
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
If I compare
void
foo ()
{
constexpr int used = 0;
[](auto unused)
{
return used;
};
}
void
bar ()
{
constexpr int used = 0;
[](int unused)
{
return used;
};
}
then in bar mark_exp_read is called on used from check_return_expr ->
convert_for_initialization -> convert_from_assignment ->
perform_implicit_conversion_flags -> mark_rvalue_use -> mark_use ->
mark_exp_read, but for the generic lambda check_return_expr takes the goto
dependent; and doesn't mark anything.
It is only marked during instantiation of the lambda, such as when (0) as added
in between } and ; and in that case the warning is gone.
More complete testcase:
void
foo ()
{
constexpr int used = 0;
[](auto unused)
{
return used;
};
}
void
bar ()
{
constexpr int used = 0;
[](int unused)
{
return used;
};
}
void
baz ()
{
constexpr int used = 0;
[](auto unused)
{
return used;
} (0);
}
void
qux ()
{
constexpr int used = 0;
[](auto unused)
{
return used + 1;
};
}
void
corge ()
{
constexpr int used = 0;
[](auto unused)
{
return used + unused;
};
}
This shows that if the variable is used in some non-dependent expression as in
qux (and not directly in return statement), it is marked already without
instantiation, but when it is only used directly in return stmt or used in a
dependent expression, it is marked only during instantiation of the lambda.
Though, when the lambda isn't really instantiated, the variable is not really
used, so not 100% sure the warning is unwanted.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/96311] [8/9/10/11 Regression] false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda)
2020-07-24 15:36 [Bug c++/96311] New: false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda) tilkax at gmail dot com
` (4 preceding siblings ...)
2021-02-11 15:25 ` jakub at gcc dot gnu.org
@ 2021-03-10 17:29 ` hewillk at gmail dot com
2021-04-05 20:04 ` jason at gcc dot gnu.org
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: hewillk at gmail dot com @ 2021-03-10 17:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96311
康桓瑋 <hewillk at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |hewillk at gmail dot com
--- Comment #5 from 康桓瑋 <hewillk at gmail dot com> ---
*** Bug 99361 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/96311] [8/9/10/11 Regression] false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda)
2020-07-24 15:36 [Bug c++/96311] New: false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda) tilkax at gmail dot com
` (5 preceding siblings ...)
2021-03-10 17:29 ` hewillk at gmail dot com
@ 2021-04-05 20:04 ` jason at gcc dot gnu.org
2021-04-05 21:27 ` cvs-commit at gcc dot gnu.org
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu.org @ 2021-04-05 20:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96311
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |jason at gcc dot gnu.org
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/96311] [8/9/10/11 Regression] false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda)
2020-07-24 15:36 [Bug c++/96311] New: false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda) tilkax at gmail dot com
` (6 preceding siblings ...)
2021-04-05 20:04 ` jason at gcc dot gnu.org
@ 2021-04-05 21:27 ` cvs-commit at gcc dot gnu.org
2021-04-05 21:29 ` [Bug c++/96311] [8/9/10 " jason at gcc dot gnu.org
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-04-05 21:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96311
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:
https://gcc.gnu.org/g:b07dd9b0d0e501a0083da79e2bca17041c007ec8
commit r11-7995-gb07dd9b0d0e501a0083da79e2bca17041c007ec8
Author: Jason Merrill <jason@redhat.com>
Date: Mon Apr 5 16:22:51 2021 -0400
c++: -Wunused, constant, and generic lambda [PR96311]
We never called mark_use for a return value in a function with dependent
return type. In that situation we don't know if the use is as an rvalue or
lvalue, but we can use mark_exp_read instead.
gcc/cp/ChangeLog:
PR c++/96311
* typeck.c (check_return_expr): Call mark_exp_read in dependent
case.
gcc/testsuite/ChangeLog:
PR c++/96311
* g++.dg/cpp1y/lambda-generic-Wunused.C: New test.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/96311] [8/9/10 Regression] false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda)
2020-07-24 15:36 [Bug c++/96311] New: false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda) tilkax at gmail dot com
` (7 preceding siblings ...)
2021-04-05 21:27 ` cvs-commit at gcc dot gnu.org
@ 2021-04-05 21:29 ` jason at gcc dot gnu.org
2021-05-14 9:53 ` [Bug c++/96311] [9/10 " jakub at gcc dot gnu.org
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu.org @ 2021-04-05 21:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96311
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |11.0
Summary|[8/9/10/11 Regression] |[8/9/10 Regression] false
|false positive for |positive for
|-Wunused-but-set-variable |-Wunused-but-set-variable
|(const/constexpr identifier |(const/constexpr identifier
|used in generic lambda) |used in generic lambda)
--- Comment #7 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for 11 so far.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/96311] [9/10 Regression] false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda)
2020-07-24 15:36 [Bug c++/96311] New: false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda) tilkax at gmail dot com
` (8 preceding siblings ...)
2021-04-05 21:29 ` [Bug c++/96311] [8/9/10 " jason at gcc dot gnu.org
@ 2021-05-14 9:53 ` jakub at gcc dot gnu.org
2021-05-20 21:35 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-05-14 9:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96311
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|8.5 |9.4
--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 8 branch is being closed.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/96311] [9/10 Regression] false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda)
2020-07-24 15:36 [Bug c++/96311] New: false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda) tilkax at gmail dot com
` (9 preceding siblings ...)
2021-05-14 9:53 ` [Bug c++/96311] [9/10 " jakub at gcc dot gnu.org
@ 2021-05-20 21:35 ` cvs-commit at gcc dot gnu.org
2021-06-01 8:18 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-05-20 21:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96311
--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:
https://gcc.gnu.org/g:8909ed58700694f5ba66499739edfea90a0fc813
commit r10-9846-g8909ed58700694f5ba66499739edfea90a0fc813
Author: Jason Merrill <jason@redhat.com>
Date: Mon Apr 5 16:22:51 2021 -0400
c++: -Wunused, constant, and generic lambda [PR96311]
We never called mark_use for a return value in a function with dependent
return type. In that situation we don't know if the use is as an rvalue or
lvalue, but we can use mark_exp_read instead.
gcc/cp/ChangeLog:
PR c++/96311
* typeck.c (check_return_expr): Call mark_exp_read in dependent
case.
gcc/testsuite/ChangeLog:
PR c++/96311
* g++.dg/cpp1y/lambda-generic-Wunused.C: New test.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/96311] [9/10 Regression] false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda)
2020-07-24 15:36 [Bug c++/96311] New: false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda) tilkax at gmail dot com
` (10 preceding siblings ...)
2021-05-20 21:35 ` cvs-commit at gcc dot gnu.org
@ 2021-06-01 8:18 ` rguenth at gcc dot gnu.org
2022-05-13 17:41 ` [Bug c++/96311] [9 " cvs-commit at gcc dot gnu.org
2022-05-13 17:45 ` jason at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-06-01 8:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96311
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|9.4 |9.5
--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9.4 is being released, retargeting bugs to GCC 9.5.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/96311] [9 Regression] false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda)
2020-07-24 15:36 [Bug c++/96311] New: false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda) tilkax at gmail dot com
` (11 preceding siblings ...)
2021-06-01 8:18 ` rguenth at gcc dot gnu.org
@ 2022-05-13 17:41 ` cvs-commit at gcc dot gnu.org
2022-05-13 17:45 ` jason at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-13 17:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96311
--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:
https://gcc.gnu.org/g:aa3e2a211933efaeb6ecd0a69f196606b8a40b43
commit r9-10165-gaa3e2a211933efaeb6ecd0a69f196606b8a40b43
Author: Jason Merrill <jason@redhat.com>
Date: Mon Apr 5 16:22:51 2021 -0400
c++: -Wunused, constant, and generic lambda [PR96311]
We never called mark_use for a return value in a function with dependent
return type. In that situation we don't know if the use is as an rvalue or
lvalue, but we can use mark_exp_read instead.
gcc/cp/ChangeLog:
PR c++/96311
* typeck.c (check_return_expr): Call mark_exp_read in dependent
case.
gcc/testsuite/ChangeLog:
PR c++/96311
* g++.dg/cpp1y/lambda-generic-Wunused.C: New test.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/96311] [9 Regression] false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda)
2020-07-24 15:36 [Bug c++/96311] New: false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda) tilkax at gmail dot com
` (12 preceding siblings ...)
2022-05-13 17:41 ` [Bug c++/96311] [9 " cvs-commit at gcc dot gnu.org
@ 2022-05-13 17:45 ` jason at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu.org @ 2022-05-13 17:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96311
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #12 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for 9.5/10.4/11.
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2022-05-13 17:45 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-24 15:36 [Bug c++/96311] New: false positive for -Wunused-but-set-variable (const/constexpr identifier used in generic lambda) tilkax at gmail dot com
2020-07-27 7:11 ` [Bug c++/96311] " marxin at gcc dot gnu.org
2020-07-27 7:40 ` tilkax at gmail dot com
2020-07-27 10:09 ` [Bug c++/96311] [8/9/10/11 Regression] " jakub at gcc dot gnu.org
2020-07-27 10:17 ` jakub at gcc dot gnu.org
2021-02-11 15:25 ` jakub at gcc dot gnu.org
2021-03-10 17:29 ` hewillk at gmail dot com
2021-04-05 20:04 ` jason at gcc dot gnu.org
2021-04-05 21:27 ` cvs-commit at gcc dot gnu.org
2021-04-05 21:29 ` [Bug c++/96311] [8/9/10 " jason at gcc dot gnu.org
2021-05-14 9:53 ` [Bug c++/96311] [9/10 " jakub at gcc dot gnu.org
2021-05-20 21:35 ` cvs-commit at gcc dot gnu.org
2021-06-01 8:18 ` rguenth at gcc dot gnu.org
2022-05-13 17:41 ` [Bug c++/96311] [9 " cvs-commit at gcc dot gnu.org
2022-05-13 17:45 ` jason at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).