public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96507] New: Feature request: improve "-Waddress" (or equivalent) for function references inside structs
@ 2020-08-06 16:43 federico.kircheis at gmail dot com
2021-11-22 17:05 ` [Bug c++/96507] missing -Waddress for member references msebor at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: federico.kircheis at gmail dot com @ 2020-08-06 16:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96507
Bug ID: 96507
Summary: Feature request: improve "-Waddress" (or equivalent)
for function references inside structs
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: federico.kircheis at gmail dot com
Target Milestone: ---
This is a feature request.
I'm compiling the code with "-Wall -Wextra -pedantic"
----
#include <utility>
void foo(){}
int main(){
void(&f)() = foo;
static_assert(!std::is_pointer<decltype(f)>::value, "should not be a
pointer");
return f != 0;
}
----
gcc correctly triggers the warning "warning: the address of 'void foo()' will
never be NULL [-Waddress]" (nitpick nullptr in the error message would be
better than NULL).
Also for following example gcc emits the desired diagnostic
----
#include <utility>
void foo(){}
using fun = void();
fun& get_fun();
int main(){
fun& f = get_fun();
static_assert(!std::is_pointer<decltype(f)>::value, "should not be a
pointer");
return f != 0;
}
----
But if the function reference is inside a struct:
----
#include <utility>
void foo(){}
using fun = void();
struct s{
fun& f;
};
s get_fun();
int main(){
s ss = get_fun();
static_assert(!std::is_pointer<decltype(ss.f)>::value, "should not be a
pointer");
return ss.f != 0;
}
----
then gcc does not emit any diagnostic (notice: it does if it can inline
get_fun()), even if "knows" that it cannot be null, as the static_assert does
not fire.
As reference: https://godbolt.org/z/vqohqM
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/96507] missing -Waddress for member references
2020-08-06 16:43 [Bug c++/96507] New: Feature request: improve "-Waddress" (or equivalent) for function references inside structs federico.kircheis at gmail dot com
@ 2021-11-22 17:05 ` msebor at gcc dot gnu.org
2021-11-22 23:56 ` msebor at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-11-22 17:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96507
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Summary|Feature request: improve |missing -Waddress for
|"-Waddress" (or equivalent) |member references
|for function references |
|inside structs |
CC| |msebor at gcc dot gnu.org
Last reconfirmed| |2021-11-22
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed with GCC 12. Since the warning is issued for non-member references
(the first case below) but not for members (the second case) I would consider
this a bug rather than an enhancement request.
$ cat pr96507.C && gcc -S -Wall pr96507.C
typedef void F ();
extern F &fr;
extern int &ir;
bool gfun ()
{
return &fr != 0; // -Waddress (expected)
}
bool gvar ()
{
return &ir != 0; // -Waddress (expected)
}
struct S
{
F &fr;
int &ir;
};
extern S s;
bool hfun ()
{
return &s.fr != 0; // missing warning
}
bool hvar ()
{
return &s.ir != 0; // missing warning
}
pr96507.C: In function ‘bool gfun()’:
pr96507.C:8:14: warning: the compiler can assume that the address of ‘fr’ will
never be NULL [-Waddress]
8 | return &fr != 0; // -Waddress (expected)
| ~~~~^~~~
pr96507.C:3:11: note: ‘fr’ declared here
3 | extern F &fr;
| ^~
pr96507.C: In function ‘bool gvar()’:
pr96507.C:13:14: warning: the compiler can assume that the address of ‘ir’ will
never be NULL [-Waddress]
13 | return &ir != 0; // -Waddress (expected)
| ~~~~^~~~
pr96507.C:4:13: note: ‘ir’ declared here
4 | extern int &ir;
| ^~
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/96507] missing -Waddress for member references
2020-08-06 16:43 [Bug c++/96507] New: Feature request: improve "-Waddress" (or equivalent) for function references inside structs federico.kircheis at gmail dot com
2021-11-22 17:05 ` [Bug c++/96507] missing -Waddress for member references msebor at gcc dot gnu.org
@ 2021-11-22 23:56 ` msebor at gcc dot gnu.org
2021-11-23 22:37 ` cvs-commit at gcc dot gnu.org
2021-11-23 22:42 ` msebor at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-11-22 23:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96507
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |msebor at gcc dot gnu.org
Status|NEW |ASSIGNED
Keywords| |patch
--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Patch: https://gcc.gnu.org/pipermail/gcc-patches/2021-November/585178.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/96507] missing -Waddress for member references
2020-08-06 16:43 [Bug c++/96507] New: Feature request: improve "-Waddress" (or equivalent) for function references inside structs federico.kircheis at gmail dot com
2021-11-22 17:05 ` [Bug c++/96507] missing -Waddress for member references msebor at gcc dot gnu.org
2021-11-22 23:56 ` msebor at gcc dot gnu.org
@ 2021-11-23 22:37 ` cvs-commit at gcc dot gnu.org
2021-11-23 22:42 ` msebor at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-23 22:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96507
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:
https://gcc.gnu.org/g:2dd56aed3e4e1938a9020ab2fe6a410e1a1c2eb3
commit r12-5484-g2dd56aed3e4e1938a9020ab2fe6a410e1a1c2eb3
Author: Martin Sebor <msebor@redhat.com>
Date: Tue Nov 23 15:35:31 2021 -0700
Issue -Waddress also for reference members [PR96507].
Resolves:
PR c++/96507 - missing -Waddress for member references
gcc/cp/ChangeLog:
PR c++/96507
* typeck.c (warn_for_null_address): Handle reference members.
gcc/testsuite/ChangeLog:
PR c++/96507
* g++.dg/warn/Waddress-8.C: New test.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/96507] missing -Waddress for member references
2020-08-06 16:43 [Bug c++/96507] New: Feature request: improve "-Waddress" (or equivalent) for function references inside structs federico.kircheis at gmail dot com
` (2 preceding siblings ...)
2021-11-23 22:37 ` cvs-commit at gcc dot gnu.org
@ 2021-11-23 22:42 ` msebor at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-11-23 22:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96507
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |12.0
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
Fixed in GCC 12.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-11-23 22:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-06 16:43 [Bug c++/96507] New: Feature request: improve "-Waddress" (or equivalent) for function references inside structs federico.kircheis at gmail dot com
2021-11-22 17:05 ` [Bug c++/96507] missing -Waddress for member references msebor at gcc dot gnu.org
2021-11-22 23:56 ` msebor at gcc dot gnu.org
2021-11-23 22:37 ` cvs-commit at gcc dot gnu.org
2021-11-23 22:42 ` msebor 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).