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

    <tr>
        <th>Summary</th>
        <td>
            Unexpected behavior after using std::string(const char *, size_t) ctor and std::string::operator+(std::string)
        </td>
    </tr>

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

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

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

<pre>
    My use-case is dealing with a fixed-size string in a file which is padded with '\0's unless it's at max size, in which case there is no null terminator.  Here is the reduced test-case:
```
#include <iostream>
#include <string>

int main() {
    char a[] = { 'A', 'B', 'C', 'D', '\0', '\0', '\0', '\0', };
    std::string b(a, 8);
    std::string c = b + "EFG";

    std::cout << a << "\n";
    std::cout << b << "\n";
    std::cout << b.c_str() << "\n";
    std::cout << c << "\n";
    std::cout << c.c_str() << "\n";

    return 0;
}
```
Compiler command:
```
clang++ -std=c++98 string_bug.cpp -o string_bug
```
Please note:  this is reproducible on all std versions.

Output:
```
ABCD
ABCD
ABCD
ABCDEFG
ABCD
```
I would expect the last line to also read "ABCDEFG".

Reproduced on the following versions of clang:
```
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: arm64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
```
```
clang version 11.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVUtv4zYQ_jXyhZAgUZFsH3SwrXVbYBddFGnRW0CRtMWCIgWSir399Z2h7DpNnEWzhmA-hjPzzbuz4lvz5RuZvEw585IoT4RkWpkjOanQE0YO6ixF6tXfkvjgkKBMvNaSnHrFe-QZmRBSzCwJXSbVLofFk8lo6T1RIZ5YIAM7E5SV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