public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dcb314 at hotmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/80711] warn on non-const accessor member functions
Date: Sat, 09 May 2020 08:36:32 +0000 [thread overview]
Message-ID: <bug-80711-4-azuVdj5FxR@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-80711-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80711
--- Comment #8 from David Binderman <dcb314 at hotmail dot com> ---
(In reply to Jonathan Wakely from comment #7)
> struct indirect_cmp {
> static int counter;
> bool operator()(const X* l, const X* r) {
> ++counter;
> return *l < *r;
> }
> };
>
> int indirect_cmp::counter = 0;
>
> So the pure attribute isn't the right property.
I tried your code on cppcheck and much to my surprise it found
the problem:
$ /home/dcb/cppcheck/trunk//cppcheck --enable=all --inconclusive may9a.cc
may9a.cc:4:8: style:inconclusive: Technically the member function
'indirect_cmp::operator()' can be const. [functionConst]
bool operator()(const X* l, const X* r) {
^
$
My working assumption had been that cppcheck was looking for C++
member functions that consist of a return statement only but clearly
it is doing more than that.
If there is any interest, I could probably figure out the pattern of C++
code it is looking for.
My opinion is that a first approximation at implementation in gcc would
merely look for C++ member functions that are return statements only.
More fancy things could be done later in a second version.
next prev parent reply other threads:[~2020-05-09 8:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <bug-80711-4@http.gcc.gnu.org/bugzilla/>
2020-05-08 15:57 ` msebor at gcc dot gnu.org
2020-05-08 17:55 ` dcb314 at hotmail dot com
2020-05-09 0:05 ` msebor at gcc dot gnu.org
2020-05-09 8:25 ` redi at gcc dot gnu.org
2020-05-09 8:36 ` dcb314 at hotmail dot com [this message]
2020-05-09 18:55 ` redi at gcc dot gnu.org
2020-05-09 20:27 ` dcb314 at hotmail dot com
2020-05-10 8:42 ` redi at gcc dot gnu.org
2020-05-10 8:52 ` redi at gcc dot gnu.org
2020-05-10 9:45 ` dcb314 at hotmail dot com
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=bug-80711-4-azuVdj5FxR@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/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).