| Issue |
87300
|
| Summary |
False report modernize-return-braced-init-list with std::string and incorrect fix is applied
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
jackua22
|
The issue is reproducible with clang 17 and 18.
This file
#include <string>
std::string space(size_t n) {
return std::string(n, ' ');
}
generates a warning
warning: avoid repeating the return type from the declaration; use a braced initializer list instead [modernize-return-braced-init-list]
And with auto-fix, tidy modifies it with the following diff
< return std::string(n, ' ');
---
> return {n, ' '};
Then the compilation fails:
error: non-constant-_expression_ cannot be narrowed from type 'size_t' (aka 'unsigned long') to 'char' in initializer list [-Wc++11-narrowing]
To reproduce:
clang-tidy '--checks=modernize-return-braced-init-list' --fix str.cpp -- -std=c++17 -stdlib=libc++
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs