a short null dereference story

Walter Bright newshound2 at digitalmars.com
Mon Dec 8 02:58:48 UTC 2025


On 12/5/2025 12:58 PM, Basile B. wrote:
> So for D the equivalent would be to generate a check on each DotVarExp.

```d
struct S { int a; }

int main()
{
     S* s = null;
     return s.a;
}
```

compile:

dmd test.d -g

run:

gdb test
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.3) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from test...done.
(gdb) run
Starting program: /home/walter/forks/dmd/compiler/src/bug2/test
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
D main () at ./test.d:8
8           return s.a;



More information about the Digitalmars-d mailing list