https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115313
Bug ID: 115313
Summary: False positive -fanalyzer use of uninitialized value
due to std::string's default constructor
Product: gcc
Version: 14.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: llvm at rifkin dot dev
Target Milestone: ---
#include <string>
#include <string_view>
namespace foo {
namespace detail {
std::string format(const char*, const char*) {
std::string str;
return str;
}
}
std::string format(std::string_view fmt) {
return detail::format(fmt.begin(), fmt.end());
}
}
int main() {
foo::format("");
}
<source>: In function 'std::string foo::detail::format(const char*, const
char*)':
<source>:7:25: warning: use of uninitialized value '<unknown>' [CWE-457]
[-Wanalyzer-use-of-uninitialized-value]
7 | std::string str;
| ^~~
'std::string foo::detail::format(const char*, const char*)': events 1-3
|
| 6 | std::string format(const char*, const char*) {
| | ^~~
| | |
| | (1) region created on stack here
| | (2) capacity: 8 bytes
| 7 | std::string str;
| | ~~~
| | |
| | (3) use of uninitialized value '<unknown>'
here
|
<source>: In function 'std::string foo::format(std::string_view)':
<source>:13:53: warning: use of uninitialized value '<unknown>' [CWE-457]
[-Wanalyzer-use-of-uninitialized-value]
13 | return detail::format(fmt.begin(), fmt.end());
| ^
'std::string foo::format(std::string_view)': events 1-3
|
| 12 | std::string format(std::string_view fmt) {
| | ^~~
| | |
| | (1) region created on stack here
| | (2) capacity: 8 bytes
| 13 | return detail::format(fmt.begin(), fmt.end());
| | ~
| | |
| | (3) use of
uninitialized value '<unknown>' here
|
<source>:13:53: warning: use of uninitialized value '<unknown>' [CWE-457]
[-Wanalyzer-use-of-uninitialized-value]
13 | return detail::format(fmt.begin(), fmt.end());
| ^
'int main()': events 1-4
|
| 18 | int main() {
| | ^~~~
| | |
| | (1) entry to 'main'
| 19 | foo::format("");
| | ~~~~~~~~~~~~~~~
| | |
| | (2) calling
'std::basic_string_view<char>::basic_string_view' from 'main'
| | (3) returning to 'main' from
'std::basic_string_view<char>::basic_string_view'
| | (4) calling 'foo::format' from 'main'
|
+--> 'std::string foo::format(std::string_view)': events 5-8
|
| 12 | std::string format(std::string_view fmt) {
| | ~~~ ^~~~~~
| | | |
| | | (5) entry to 'foo::format'
| | (6) region created on stack here
| | (7) capacity: 8 bytes
| 13 | return detail::format(fmt.begin(), fmt.end());
| | ~
| | |
| | (8) use
of uninitialized value '<unknown>' here
|
https://godbolt.org/z/enKzccqoK