http://llvm.org/bugs/show_bug.cgi?id=16088
Bug ID: 16088
Summary: Wshadow results in (correct, but unhelpful) warning
with constructor parameter having the name of data
member
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
Classification: Unclassified
The following program results in a warning about the constructor parameter <i>
shadowing Foo's data member <i> when compiled with clang r181693:
struct Foo {
int i;
Foo(int i) : i(i) {}
};
This results in:
% clang++ -v -Wshadow -c clang.cpp
clang version 3.4 (trunk 181693)
[...]
clang.cpp:4:13: warning: declaration shadows a field of 'Foo' [-Wshadow]
Foo(int i) : i(i) {}
^
clang.cpp:2:9: note: previous declaration is here
int i;
^
1 warning generated.
While the warning is correct, it is IMHO a common idiom to name the
constructor's parameters identical to the class's data member they initialize.
In that case the warning is unhelpful.
Of course there are workarounds:
1. Rename the parameters, e.g. add a trailing underscore.
2. Use C++11's uniform initialization syntax where possible.
That is why I'm not sure if clang's current behavior should be changed (one
possible change would be to only warn if the parameter is used in the
constructor's body instead of only in the member initialization list).
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs