| Issue |
164536
|
| Summary |
[clang] Segmentation fault when initializing const std::string
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
sekaiacg
|
**system:**
`ArchLinux`
**clang version:**
```
clang version 21.1.4
Target: x86_64-pc-linux-gnu
```
**gcc version:**
`15.2.1 20250813 (GCC) `
**description:**
`After compiling and running with clang, a segmentation fault occurred, but it ran normally after compiling with gcc. I found the cause after debugging with gdb. I have provided the source code for testing and hope to get some help.`
**gcc**
```
./build/test
p=en-US
skkk: ~DesktopPlatform
```
**clang**
```
./build/test
Segmentation fault (core dumped) ./build/test
```
`gdb:`
```
(gdb) where
#0 0x0000000000405cd0 in std::char_traits<char>::assign (__c1=@0x4f8b40: 0 '\000',
__c2=<error reading variable: Cannot access memory at address 0x0>)
at /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/bits/char_traits.h:352
#1 0x0000000000405ae8 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_S_copy (__d=0x4f8b40 <brls::Platform::APP_LOCALE_DEFAULT[abi:cxx11]+16> "", __s=0x0, __n=1)
at /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/bits/basic_string.h:451
#2 0x0000000000405910 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<true> (this=0x4f8b30 <brls::Platform::APP_LOCALE_DEFAULT[abi:cxx11]>, __str=0x0,
__n=0)
at /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/bits/basic_string.tcc:298
#3 0x000000000040571c in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string (this=0x4f8b30 <brls::Platform::APP_LOCALE_DEFAULT[abi:cxx11]>, __str=...)
at /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/bits/basic_string.h:617
#4 0x0000000000405145 in __cxx_global_var_init.1(void) ()
at test/platform.hpp:18
```
**test sources:**
[test.zip](https://github.com/user-attachments/files/23044910/test.zip)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs