[LLVMbugs] [Bug 16088] New: Wshadow results in (correct, but unhelpful) warning with constructor parameter having the name of data member
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Tue May 21 05:54:40 PDT 2013
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: unassignedclangbugs at nondot.org
Reporter: jonathan.sauer at gmx.de
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130521/f439dd1f/attachment.html>
More information about the llvm-bugs
mailing list