public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mail at 3v1n0 dot net" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/94554] spurious -Waddress warning within "if constexpr" function-null compares
Date: Thu, 01 Oct 2020 17:54:09 +0000	[thread overview]
Message-ID: <bug-94554-4-AL36xBFhTt@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-94554-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94554

Marco Trevisan <mail at 3v1n0 dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mail at 3v1n0 dot net

--- Comment #5 from Marco Trevisan <mail at 3v1n0 dot net> ---
I don't think g++ is totally wrong here,

Actually, if any, it should be stronger in making the error clearer and louder,
as per sé it's fine to consider that you're for real not comparing something
constant and the function address may not be known at compile time, so not
wrong to check.

However, something that will not error but work can be something like:

#include <iostream>
#include <type_traits>

using namespace std;

int meow() { return 1; }
void kitty(int i) { std::cout << "Mowed vlaue " << i << "\n"; }

template <int (*F)()>
void test() {
    using NullType = std::integral_constant<decltype(F), nullptr>;
    using ActualType = std::integral_constant<decltype(F), F>;

    if constexpr (!std::is_same_v<ActualType, NullType>) {
        kitty(F());
    } else {
        kitty(222222);
    }
}

int main()
{
    test<nullptr>();
    test<meow>();

    return 0;
}

  parent reply	other threads:[~2020-10-01 17:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-10 18:58 [Bug c++/94554] New: " myriachan at gmail dot com
2020-04-10 20:20 ` [Bug c++/94554] " mpolacek at gcc dot gnu.org
2020-04-10 20:22 ` myriachan at gmail dot com
2020-04-14 21:56 ` daniel.kruegler at googlemail dot com
2020-07-10 15:13 ` lts-rudolph at gmx dot de
2020-10-01 17:54 ` mail at 3v1n0 dot net [this message]
2022-06-23  4:25 ` jason at gcc dot gnu.org
2022-06-23  4:31 ` jason at gcc dot gnu.org
2022-06-23 15:08 ` cvs-commit at gcc dot gnu.org
2022-06-23 15:44 ` jason at gcc dot gnu.org

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-94554-4-AL36xBFhTt@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).