Skip to content

return (NULL) will give incorrect warnings with -Wimplicit-void-ptr-cast #171874

@Leont

Description

@Leont

This program:

#include <stdlib.h>

struct foo {
	char baz;
};

struct foo* bar() {
	return(NULL);
}

int main() {
	bar();
}

Will give the following warning when compiled with -Wimplicit-void-ptr-cast / -Wc++-compat

test.c:8:8: warning: implicit conversion when returning 'void *' from a function with result type 'struct foo *' is not
      permitted in C++ [-Wimplicit-void-ptr-cast]
    8 |         return(NULL);
      |               ^~~~~~
1 warning generated.

Even though it's perfectly valid C++ (because NULL isn't a void pointer C++, so the expression (NULL) won't be a void pointer either) that clang++ doesn't have any issue with.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions