llvm / llvm/llvm-project

[clang-tidy] modernize-return-braced-init-list gives misleading warning about repeated typename when returning an object with operator T&

Open
#185,044 14 comments 0 reactions 1 assignee Claimed by @gxyd View on GitHub
clang-tidy false-positive
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

https://godbolt.org/z/naeo7Y6bK

```c++
struct foo {};

struct bar {
operator const foo&() const;
};

foo x() {
return bar();
}
```

--checks=modernize-return-braced-init-list for clang-tidy, no particular flags needed for Clang.

Output:

```
:8:5: warning: avoid repeating the return type from the declaration; use a braced initializer list instead [modernize-return-braced-init-list]
8 | return bar();
| ^
1 warning generated.
```

Exactly which return type is being repeated? And how would a braced-init-list help? `return { bar() };` just errors out.

e: whoops, forgot that I renamed a type in the last line

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.