Bug 116619 - Invalid null pointer constant accepted in the initializer of a pointer
Summary: Invalid null pointer constant accepted in the initializer of a pointer
Status: RESOLVED DUPLICATE of bug 52145
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 15.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2024-09-05 18:32 UTC by Halalaluyafail3
Modified: 2024-09-05 23:25 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Halalaluyafail3 2024-09-05 18:32:22 UTC
The following code is incorrectly accepted by GCC:

int main(){
    void*p=int(0);
}

This code is invalid because int(0) is not a null pointer constant. Clang and MSVC (with /permissive-) reject this program for this reason. Also, GCC rejects this as a null pointer constant in some other contexts, for example:

#include<iostream>
void foo(void*){
    std::cout<<"1\n";
}
void foo(...){
    std::cout<<"2\n";
}
int main(){
    foo(0);
    foo(int(0));
}

GCC prints "1 2" here (correctly) since int(0) isn't treated as a null pointer constant. Though not all other contexts handle this correctly, for example static_cast<void*>(int(0)) is also incorrect accepted.
Comment 1 Andrew Pinski 2024-09-05 18:48:57 UTC
Dup, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52145#c11 for the full list; int(0) here is the same as `int{}` and `(int)0`.

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