| Issue |
180324
|
| Summary |
[clang-tidy][FN] `bugprone-string-constructor` misses valid cases due to strict argument count matching
|
| Labels |
clang-tidy
|
| Assignees |
|
| Reporter |
XGPSPL
|
**Environment:**
- Clang-Tidy Version: LLVM version 23.0.0git (Optimized build with assertions)
- Commit Hash: [`5654ecd5ddeb2f40e124a6bf10cc78230da4ef49`](https://github.com/llvm/llvm-project/commit/5654ecd5ddeb2f40e124a6bf10cc78230da4ef49)
- Platform: Linux 6.18.6
**Reproducer:**
```c++
#include <string>
#include <vector>
void test_string_constructor_allocator_fn() {
std::allocator<char> a;
// Swapped arguments with explicit allocator.
// Matcher expects argumentCountIs(2), but this has 3.
std::string s1('x', 5, a);
// Standard string constructor with default allocator argument.
// Many STL implementations (like libstdc++) define:
// string(const char*, size_type, const Allocator& = Allocator())
// resulting in 3 arguments in the AST (one default), causing argumentCountIs(2) to fail.
std::string s3("short", 100);
}
```
**Godbolt:** https://clang-tidy.godbolt.org/z/dq6Yz5z77
**Notes:** The current test suite passes because it uses a mock `basic_string` that does not include the default allocator argument present in `libstdc++`.
```
`-CXXConstructExpr 0x... <col:15, col:29> 'std::string' 'void (const char *, size_type, const std::allocator<char> &)'
|-ImplicitCastExpr 0x... <col:17> 'const char *' <ArrayToPointerDecay>
| `-StringLiteral 0x... <col:17> 'const char[6]' lvalue "short"
|-ImplicitCastExpr 0x... <col:26> 'size_type':'unsigned long' <IntegralCast>
| `-IntegerLiteral 0x... <col:26> 'int' 100
`-CXXDefaultArgExpr 0x... <<invalid sloc>> 'const std::allocator<char>' lvalue
`-MaterializeTemporaryExpr 0x...
```
**AI Usage:** This issue was found using an LLM-Assisted Fuzzer and verified by a human.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs