Bug 107260 - The prvalue with the value 0 that is not a integer literal shouldn't convert to std::nullptr_t
Summary: The prvalue with the value 0 that is not a integer literal shouldn't convert ...
Status: RESOLVED DUPLICATE of bug 52145
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2022-10-14 09:35 UTC by jim x
Modified: 2022-10-14 15:14 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2022-10-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jim x 2022-10-14 09:35:17 UTC
[conv.ptr] p1 says
> A null pointer constant is an integer literal ([lex.icon]) with value zero 

> A null pointer constant of integral type can be converted to a prvalue of type std​::​nullptr_­t.

GCC accept this example
````cpp
std::nullptr_t v = (int)0;
````
However, the initializer expression is not an integer literal, it is a prvalue of integer type with the value 0. It should be rejected. Clang rejects this example. https://godbolt.org/z/fxMo4YKE3
Comment 1 Jonathan Wakely 2022-10-14 09:59:43 UTC
(In reply to jim x from comment #0)
> GCC accept this example

Well, it does if you include a definition of std::nullptr_t

typedef decltype(nullptr) nullptr_t;
nullptr_t v = (int)0;

Not a regression, this has been accepted since 4.6.4
Comment 2 Marek Polacek 2022-10-14 13:21:28 UTC
I think this is CWG 903 and thus a dup of bug 52145.  The problem here is probably the same as I described in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77712#c2.
Comment 3 Marek Polacek 2022-10-14 13:52:12 UTC
I wonder if we could wrap the INTEGER_CST in a NOP_EXPR/V_C_E to make it clear it's not an integer literal.
Comment 4 Andrew Pinski 2022-10-14 15:14:58 UTC
Dup of bug 52145.

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