Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Clang warning is equivalent to Wzero-as-null-pointer-constant from GCC?

Our project uses C++11/14, and we want to use nullptr instead of 0 or NULL with pointers, even when 0 (as an integer literal) is allowed.

I have the following code:

int main()
{
    int *ptr1 = nullptr; // #1
    int *ptr2 = 0;       // #2
}

If I compile with GCC (5.3.0) and the flag -Wzero-as-null-pointer-constant it warnings in #2, but I can't find a similar flag in Clang. If I compile the code with Clang (3.7.1) and the flag -Weverything, I don't get any warning about #2.

So, is there any way to get a similar warning for this in Clang?

like image 474
Daniel Avatar asked Jan 22 '16 18:01

Daniel


2 Answers

clang has this warning as of 5.0; I added it here.

like image 180
thakis Avatar answered Sep 19 '22 12:09

thakis


Clang doesn't support these kind of warnings (i.e., there's no -Wzero-as-null-pointer-constant equivalent in Clang). You can see it your self if you add -Weverything option (mind do it only for testing), which enables all Clang's warnings.

Live Demo

like image 36
101010 Avatar answered Sep 19 '22 12:09

101010