public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/94510] [9/10 Regression] nullptr_t implicitly cast to zero twice in std::array
Date: Tue, 07 Apr 2020 16:08:12 +0000	[thread overview]
Message-ID: <bug-94510-4-Kns3so7gP3@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-94510-4@http.gcc.gnu.org/bugzilla/>

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

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

--- Comment #9 from Martin Sebor <msebor at gcc dot gnu.org> ---
The changed code in reshape_init_array_1 checks for integer/pointer mismatches
via the following test:

      /* Pointers initialized to strings must be treated as non-zero
         even if the string is empty.  */
      tree init_type = TREE_TYPE (elt_init);
      if (POINTER_TYPE_P (elt_type) != POINTER_TYPE_P (init_type)
          || !type_initializer_zero_p (elt_type, elt_init))
        last_nonzero = index;

...and a test case involving an ordinary pointer is diagnosed:

$ cat t.C && gcc -S -Wall t.C
int a[2] = { nullptr };
int b[2] = { (void*)0 };

t.C:2:23: error: invalid conversion from ‘void*’ to ‘int’ [-fpermissive]
    2 | int b[2] = { (void*)0 };
      |                       ^
      |                       |
      |                       void*


but a nullptr use is not.

(gdb) p debug_tree (init_type)
$6 = (tree) 0x7fffea9521f8
<nullptr_type 0x7fffea9521f8 decltype(nullptr) public unsigned DI
    size <integer_cst 0x7fffea7f7e70 type <integer_type 0x7fffea8150a8
bitsizetype> constant 64>
    unit-size <integer_cst 0x7fffea7f7e88 type <integer_type 0x7fffea815000
sizetype> constant 8>
    align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7fffea9521f8>

I would expect POINTER_TYPE_P (init_type) to be non-zero but it's not:

(gdb) p POINTER_TYPE_P (init_type)
$7 = false

  parent reply	other threads:[~2020-04-07 16:08 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-07  8:23 [Bug c++/94510] New: " kndevl at outlook dot com
2020-04-07  8:24 ` [Bug c++/94510] " kndevl at outlook dot com
2020-04-07  8:24 ` kndevl at outlook dot com
2020-04-07  8:25 ` kndevl at outlook dot com
2020-04-07  8:25 ` kndevl at outlook dot com
2020-04-07  8:26 ` kndevl at outlook dot com
2020-04-07  8:30 ` kndevl at outlook dot com
2020-04-07  8:30 ` kndevl at outlook dot com
2020-04-07 11:59 ` [Bug c++/94510] [9/10 Regression] " redi at gcc dot gnu.org
2020-04-07 16:08 ` msebor at gcc dot gnu.org [this message]
2020-04-07 18:51 ` msebor at gcc dot gnu.org
2020-04-22  6:28 ` cvs-commit at gcc dot gnu.org
2020-04-22  6:29 ` [Bug c++/94510] [9 " jason at gcc dot gnu.org
2020-04-22 20:39 ` cvs-commit at gcc dot gnu.org
2020-04-22 21:56 ` 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-94510-4-Kns3so7gP3@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).