https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86176
Bug ID: 86176
Summary: Wnull-dereference warning disappears with a call to
std::cout on the line after
Product: gcc
Version: 8.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jg at jguk dot org
Target Milestone: ---
Hello
Some possible issues. Could you give your opinion please.
1. printf Wnull-dereference warning is only visible with -O2 (not -O0)
2. printf Wnull-dereference warning disappears if I uncomment the std::cout on
line after.
There is bug 86172 but I have not linked it.
note, I also tried g++8.1 x86-64, same results.
g++-8 --version
g++-8 (Ubuntu 8-20180414-1ubuntu2) 8.0.1 20180414 (experimental) [trunk
revision 259383]
jonny@asus:~/code$ g++-8 -O0 -Wall -Wextra -Wnull-dereference -Wpedantic -o
main.o -c main.cpp
jonny@asus:~/code$ g++-8 -O2 -Wall -Wextra -Wnull-dereference -Wpedantic -o
main.o -c main.cpp
main.cpp: In function ‘int main()’:
main.cpp:8:11: warning: null pointer dereference [-Wnull-dereference]
printf("%d\n", *i);
~~~~~~^~~~~~~~~~~~
jonny@asus:~/code$
#include <stdio.h>
#include <iostream>
void f(const int *i)
{
printf("%d\n", *i);
//std::cout << *i;
}
int main () {
f(nullptr);
return 0;
}