https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117329

--- Comment #4 from Oskars Putans <o.putaans at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> I can't reproduce the warning for Wnull-dereference but I do get a warning
> for -O2 -Warray-bounds  that has the same line as what you reported.

Oh no.. It seems that I've accidentally submitted the wrong version of the
file.

Here's the real file. The only difference is in the struct Test there isn't an
int member variable. That causes an offset in the struct making the member
variable's location a not remain a nullptr, but a nullptr + sizeof(int) (not
accounting for byte alignments or other offsets). Still suspicious as the
array-bounds warning is even more cryptic :P
```
# 0 "main.cpp"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "main.cpp"
struct T2 {
  int var;
  void setVar(int a) { var = a; }
};

struct Test {
  T2 *getA() { return &a; }
  T2 a;
};

int main() {
  Test *t = nullptr;
  t->getA()->setVar(5);
  return 0;
}
```

Reply via email to