GCC analyzer false positive

Zachary Yedidia zyedidia at gmail.com
Thu Aug 31 13:53:55 UTC 2023


The following code generates a warning when using GCC analyzer, 
but I don't think the warning is valid.

```
struct Guard {
     ~this() {}
}
Guard lock() {
     return Guard();
}
void bar() {
     auto foo = lock();
}
```

Compiled with GCC version 13.1:

```
$ gdc -fanalyzer test.d -O2 -c
test.d: In function 'lock':
test.d:5:5: warning: use of uninitialized value 'MEM[(unsigned 
char * {ref-all})&D.3438]' [CWE-457] 
[-Wanalyzer-use-of-uninitialized-value]
     5 |     return Guard();
       |     ^
   'lock': events 1-2
     |
     |    5 |     return Guard();
     |      |     ^
     |      |     |
     |      |     (1) region created on stack here
     |      |     (2) use of uninitialized value 'MEM[(unsigned 
char * {ref-all})&D.3438]' here
     |
```

Any ideas? Thanks!


More information about the D.gnu mailing list