<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58991>58991</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang Static Analyzer emits spurious uninitialized-value warnings when dealing with const objects as return-codes
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          jfriesne
      </td>
    </tr>
</table>

<pre>
    (Background:  this issue was originally a StackOverflow question, as seen at this [link](https://stackoverflow.com/questions/74427095/is-there-a-way-for-me-to-help-clang-static-analyzer-understand-global-constant-o).  Since it appears to be a ClangSA bug, or at least a ClangSA shortcoming, I'm filing a GitHub issue about it as well)

To reproduce:

1) Unzip the attached file `clang_sa_spurious_warning_source_code.zip`.  It contains one .cpp file and one .h file, each with about two dozen lines of toy code in it.
2) Run this command from the same directory:
       `scan-build g++ -std=c++17 ./my_test_program.cpp` 
3) Observe that you get the following warning text:
```
./my_test_program.cpp:21:4: warning: 2nd function call argument is an uninitialized value [core.CallAndMessage]
             printf("ret=%i\n", ret);
```
Expected behavior is that no warning should be issued, since in the case where the `GetValue()` method returns `STATUS_DATA_NOT_FOUND`, the `IsError()` method will return `true` and `ret = 42;` will execute, and in the case where `GetValue()` returns `STATUS_NO_ERROR`, `ret = 42` will have been executed inside `GetValue()`.  In both cases, the `ret` variable will have been initialized to a well-defined value before it is passed to `printf()`.
4) Note that if your edit `my_status_t_class.h` and replace the definitions of `STATUS_NO_ERROR` and `STATUS_DATA_NOT_FOUND` with `#define` macros, that ClangSA will then function as expected and note emit a spurious warning:

     #define STATUS_NO_ERROR       status_t(0)
     #define STATUS_DATA_NOT_FOUND status_t(-1)

[clang_sa_spurious_warning_source_code.zip](https://github.com/llvm/llvm-project/files/10007845/clang_sa_spurious_warning_source_code.zip)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org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