From: Jason Merrill <jason@redhat.com>
To: Martin Sebor <msebor@gmail.com>,
gcc-patches <gcc-patches@gcc.gnu.org>,
"Joseph S. Myers" <joseph@codesourcery.com>,
Jeff Law <jeffreyalaw@gmail.com>
Subject: Re: [PATCH] warn for more impossible null pointer tests [PR102103]
Date: Tue, 21 Sep 2021 17:40:14 -0400 [thread overview]
Message-ID: <20fcad1c-a129-0d8a-d2fb-aac353c3089b@redhat.com> (raw)
In-Reply-To: <8526359b-bbd7-3de9-d74f-71005fbefb1d@gmail.com>
On 9/17/21 12:02, Martin Sebor wrote:
> On 9/8/21 2:06 PM, Jason Merrill wrote:
>> On 9/2/21 7:53 PM, Martin Sebor wrote:
>>> @@ -4622,28 +4622,94 @@ warn_for_null_address (location_t location,
>>> tree op, tsubst_flags_t complain)
>>> if (!warn_address
>>> || (complain & tf_warning) == 0
>>> || c_inhibit_evaluation_warnings != 0
>>> - || warning_suppressed_p (op, OPT_Waddress))
>>> + || warning_suppressed_p (op, OPT_Waddress)
>>> + || processing_template_decl != 0)
>>
>> Completely suppressing this warning in templates seems like a
>> regression; I'd think we could recognize many relevant cases before
>> instantiation. You just can't assume that ADDR_EXPR has the default
>> meaning if it has unknown type (i.e. because op0 is type-dependent).
>
> I added the suppression to keep g++.dg/warn/pr101219.C from failing
> but in hindsight I should have questioned the reasoning behind
> the "no warning emitted here (no instantiation)" comment in the test.
>
> I agree that it would be helpful to diagnose the type-independent
> subset of the problem even in uninstantiated templates. Current
> trunk doesn't (it never has), but with my patch and the suppression
> above removed it does. I've updated the tests to expect it.
>
> Please see the attached revision.
>
> Martin
>
> PS There are still more opportunities to issue -Waddress in templates
> that this patch doesn't handle, e.g.,:
>
> template <class T> bool f (T *p) { return &p == 0; }
>
> Handling this will take more surgery.
>
> PPS It seems that most other warnings (and even some errors, like
> -Wnarrowing) are suppressed in uninstantiated templates as well,
> even for non-dependent expressions. In the few test cases I looked
> at Clang does better. It sounds like you'd like to see improvements
> in this direction not just for -Waddress but in general. Just for
> the avoidance of doubt, can you confirm that for future reference?
Yes, in general it's better to diagnose sooner.
> + if (TREE_CODE (cop) == NON_LVALUE_EXPR)
> + /* Unwrap the expression for C++ 98. */
> + cop = TREE_OPERAND (cop, 0);
What does this have to do with C++98?
> + if (TREE_CODE (cop) == PTRMEM_CST)
> + {
> + /* The address of a nonstatic data member is never null. */
> + warning_at (location, OPT_Waddress,
> + "the address %qE will never be NULL",
Capitalizing NULL when talking about pointers-to-members seems a bit
odd, but I guess it's fine.
The C++ changes are OK.
Jason
next prev parent reply other threads:[~2021-09-21 21:40 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-01 2:08 [PATCH] warn for more impossible null pointer tests Martin Sebor
2021-09-01 17:35 ` Jeff Law
2021-09-01 18:57 ` Koning, Paul
2021-09-01 19:08 ` Jeff Law
2021-09-01 19:28 ` Koning, Paul
2021-09-01 19:35 ` Iain Sandoe
2021-09-01 19:58 ` Andreas Schwab
2021-09-01 20:36 ` Koning, Paul
2021-09-01 19:21 ` Jason Merrill
2021-09-01 20:33 ` Martin Sebor
2021-09-01 21:39 ` Jason Merrill
2021-09-01 22:27 ` Martin Sebor
2021-09-02 13:43 ` Jason Merrill
2021-09-02 14:39 ` Martin Sebor
2021-09-02 23:53 ` [PATCH] warn for more impossible null pointer tests [PR102103] Martin Sebor
2021-09-08 20:06 ` Jason Merrill
2021-09-17 16:02 ` Martin Sebor
2021-09-21 21:40 ` Jason Merrill [this message]
2021-09-22 0:34 ` Martin Sebor
2021-09-22 20:12 ` Jason Merrill
2021-09-24 14:31 ` PING " Martin Sebor
2021-09-30 16:14 ` PING #2 " Martin Sebor
2021-09-30 19:35 ` Joseph Myers
2021-10-01 17:58 ` Martin Sebor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20fcad1c-a129-0d8a-d2fb-aac353c3089b@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jeffreyalaw@gmail.com \
--cc=joseph@codesourcery.com \
--cc=msebor@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).