Bug 77712 (dr903) - [DR903] int() is incorrectly treated as a null pointer constant in C++11 and later
Summary: [DR903] int() is incorrectly treated as a null pointer constant in C++11 and ...
Status: RESOLVED DUPLICATE of bug 52145
Alias: dr903
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: accepts-invalid
Depends on:
Reported: 2016-09-23 15:32 UTC by TC
Modified: 2021-12-04 06:43 UTC (History)
3 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2021-07-27 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description TC 2016-09-23 15:32:03 UTC
GCC accepts

int *p = int();

even though per DR 903, only integer literals with the value zero are null pointer constants.

This causes http://stackoverflow.com/q/39662995/2756719.
Comment 1 Jonathan Wakely 2018-02-02 16:20:16 UTC
This should be accepted in C++03 mode but rejected in C++11 and later (as I think we treat DR 903 as a DR against C++11)
Comment 2 Marek Polacek 2019-08-02 20:57:21 UTC
The problem here is that parsing "int()" results in INTEGER_CST 0, created by build_zero_init, and we have no way to tell that it's not a null pointer constant anymore :(.
Comment 3 Andrew Pinski 2021-12-04 06:43:57 UTC
Dup of bug 52145.

*** This bug has been marked as a duplicate of bug 52145 ***