public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94510] New: nullptr_t implicitly cast to zero twice in std::array
@ 2020-04-07  8:23 kndevl at outlook dot com
  2020-04-07  8:24 ` [Bug c++/94510] " kndevl at outlook dot com
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: kndevl at outlook dot com @ 2020-04-07  8:23 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94510
           Summary: nullptr_t implicitly cast to zero twice in std::array
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kndevl at outlook dot com
  Target Milestone: ---

`std::array<int, 3> arr{ nullptr, 0, 0 };` is expected to fail to compile
similar to how `std::array<int, 3> arr{ nullptr, 0, 1 };` fails. What I infer
is that if all elements are effectively zero, type conversions are not checked.
This makes sense if a variable of static storage duration is initialized to
zero and std::array constructor can ignore the arguments in the initializer if
all arguments are implicitly zero. 

Is there anything on the C++ standard that allows this optimization I am
missing here?

# This works fine, as expected

`g++ -save-temps -c not-bug.cpp`

> not-bug.cpp: In function ‘void test()’:
> not-bug.cpp:4:43: error: cannot convert ‘std::nullptr_t’ to ‘int’ in initialization
>     4 |     std::array<int, 3> arr{ nullptr, 0, 1 };

# This compiles fine, but this should error out

`g++ -save-temps -c bug.cpp`


I built the tip of gcc yesterday. It had the same bug.
Any pointers on how I can go about debugging this? 
- Does type checking happen during GENERIC stage?
- How do I print the source string corresponding to a TREE struct?

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2020-04-22 21:56 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-07  8:23 [Bug c++/94510] New: nullptr_t implicitly cast to zero twice in std::array 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
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

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).