<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Wshadow results in (correct, but unhelpful) warning with constructor parameter having the name of data member"
   href="http://llvm.org/bugs/show_bug.cgi?id=16088">16088</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Wshadow results in (correct, but unhelpful) warning with constructor parameter having the name of data member
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jonathan.sauer@gmx.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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).</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>