<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/152026>152026</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`bugprone-exception-escape` for `std::string` member in default copy constructor invocation reported with libc++
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
firewave
</td>
</tr>
</table>
<pre>
```cpp
#include <string>
struct CallBase {
std::string callId;
};
void f() noexcept
{
CallBase cb;
CallBase cb1 = cb;
}
```
```
<source>:7:6: warning: an exception may be thrown in function 'f' which should not throw exceptions [bugprone-exception-escape]
7 | void f() noexcept
| ^
/opt/compiler-explorer/clang-trunk-20250804/bin/../include/c++/v1/stdexcept:243:3: note: frame #0: unhandled exception of type 'std::length_error' may be thrown in function '__throw_length_error' here
243 | throw length_error(__msg);
| ^
/opt/compiler-explorer/clang-trunk-20250804/bin/../include/c++/v1/string:2477:5: note: frame #1: function '__throw_length_error' calls function '__throw_length_error' here
2477 | std::__throw_length_error("basic_string");
| ^
/opt/compiler-explorer/clang-trunk-20250804/bin/../include/c++/v1/string:2583:7: note: frame #2: function '__init_copy_ctor_external' calls function '__throw_length_error' here
2583 | this->__throw_length_error();
| ^
/opt/compiler-explorer/clang-trunk-20250804/bin/../include/c++/v1/string:997:7: note: frame #3: function 'basic_string' calls function '__init_copy_ctor_external' here
997 | __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
| ^
<source>:3:8: note: frame #4: function 'CallBase' calls function 'basic_string' here
3 | struct CallBase {
| ^
<source>:10:20: note: frame #5: function 'f' calls function 'CallBase' here
10 | CallBase cb1 = cb;
| ^
```
https://godbolt.org/z/G75sj5fYz
This is only reported with libc++.
Somewhat related to #109587.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzElkGTsygTxz8NuXQlRUCjOeTgzDy-9Z53L3uyENvI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