llvm / llvm/llvm-project

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

Open
#171,874 2 comments 0 reactions 0 assignees View on GitHub
clang:diagnostics
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

This program:
```
#include

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.

Contributor guide

Open the contributing guide

Research direction

Start by compiling the supplied program with the C compiler using -Wimplicit-void-ptr-cast and -Wc++-compat, then compare the result with clang++. Trace the diagnostic handling for this warning and verify that valid C++ use of return(NULL) no longer produces the incorrect warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.