`-Wshadow-field` reported instead of `-Wshadow-field-in-constructor` with fields from base class
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
```cpp
class Base
{
protected:
Base(bool b) : b(b) {}
bool b;
};
class Derived : public Base
{
public:
Derived(bool b) : Base(b) {}
};
```
```
:4:15: warning: constructor parameter 'b' shadows the field 'b' of 'Base' [-Wshadow-field-in-constructor]
4 | Base(bool b) : b(b) {}
| ^
:5:10: note: previous declaration is here
5 | bool b;
| ^
:11:18: warning: parameter 'b' shadows member inherited from type 'Base' [-Wshadow-field]
11 | Derived(bool b) : Base(b) {}
| ^
:5:10: note: declared here
5 | bool b;
| ^
``
https://godbolt.org/z/aKbqxGdE9
I would have expected `-Wshadow-field-in-constructor` in both cases.
Contributor guide
Research direction
Start with the provided C++ reproducer in the linked Godbolt example and compare the diagnostics for the base and derived constructors. Trace Clang's shadow-warning handling to determine why the inherited-field case uses -Wshadow-field; done means both constructor parameters receive the expected -Wshadow-field-in-constructor diagnostic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100