<html>
    <head>
      <base href="https://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 --- - ParmVarDecl corresponding to unnamed parameter incorrectly has a name"
   href="https://llvm.org/bugs/show_bug.cgi?id=29145">29145</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ParmVarDecl corresponding to unnamed parameter incorrectly has a name
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </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>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>lukasza@chromium.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>clang version 4.0.0 (trunk 277962)

Expected behavior:

    1. The ParmVarDecl corresponding to
           void f(int);
       declaration on line 5 should have
       1) no identifier
       2) no name

    2. I can safely generate replacements of text inside parm.getLocation() 
       (e.g. rename "dataSize" to "data_size").

Actual behavior:

    1. There are 2 ParmVarDecls on line 5.
       One of these ParmVarDecls has a non-empty name and identifier.

    2. Generating replacements based on parm.getLocation() would
       butcher the source code.

    3. Output of the repro program below:

        Name = ''
        Identifier = '0x0'            <-- looking good so far...
        Line = 'input.cc:5:19'
        ---------------------------------
        Name = 'dataSize'             <-- THIS IS THE BUG
        Identifier = '0x3a05f98'
        Line = 'input.cc:5:19'
        ---------------------------------
        Name = ''
        Identifier = '0x0'
        Line = 'input.cc:3:13'        <- please ignore ParmVarDecls from other
lines
        ---------------------------------
        Name = 'dataSize'
        Identifier = '0x3a05f98'
        Line = 'input.cc:9:28'        <- please ignore ParmVarDecls from other
lines

Repro:

#include <memory>

#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/ASTMatchers/ASTMatchersMacros.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Refactoring.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/TargetSelect.h"

using namespace clang::ast_matchers;

class ReproMatchCallback : public MatchFinder::MatchCallback {
 public:
  void run(const MatchFinder::MatchResult& result) override {
    const clang::ParmVarDecl* parm =
result.Nodes.getNodeAs<clang::ParmVarDecl>("decl");
    if (!parm)
      return;

    llvm::outs() << "---------------------------------\n";
    llvm::outs() << "Name = '" << parm->getName() << "'\n";
    llvm::outs() << "Identifier = '" << parm->getIdentifier() << "'\n";
    llvm::outs() << "Line = '" <<
parm->getLocation().printToString(result.Context->getSourceManager()) << "'\n";
  }
};

int main(int argc, const char* argv[]) {
  llvm::InitializeNativeTarget();
  llvm::InitializeNativeTargetAsmParser();
  llvm::cl::OptionCategory category("Repro.");
  clang::tooling::CommonOptionsParser options(argc, argv, category);
  clang::tooling::ClangTool tool(options.getCompilations(),
                                 options.getSourcePathList());

  const char* code = R"code(            // line 1
      template <typename T>             // line 2
      class Class {                     // line 3
       public:                          // line 4
        void f(int);  // <- NO NAME!    // line 5
      };                                // line 6
                                        // line 7
      template <typename T>             // line 8
      void Class<T>::f(int dataSize){}; // line 9
                                        // line 10
      void foo() {                      // line 11
        Class<char>().f(123);           // line 12
      };                                // line 13
  )code";

  auto matcher = id("decl", parmVarDecl());

  MatchFinder match_finder;
  ReproMatchCallback match_callback;
  match_finder.addMatcher(matcher, &match_callback);
  std::unique_ptr<clang::tooling::FrontendActionFactory> factory =
      clang::tooling::newFrontendActionFactory(&match_finder);
  clang::tooling::runToolOnCode(factory->create(), code);
  return 0;
}</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>