<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 --- - Clang crashes when suggesting unencessary "this->" fixit"
   href="https://llvm.org/bugs/show_bug.cgi?id=24791">24791</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang crashes when suggesting unencessary "this->" fixit
          </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>Frontend
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>rtrieu@google.com
          </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>push.cpp:
struct A {
  void Run(int x) {
    Get<>(x, x);
  }

  template <typename X>
  void Get(X x, int y) {
    // correct error message
    //this->Set(x);

    // correct error message
    //Set(y);

    // compiles
    //Set(&x);

    // crash
    Set(x);
  }

  // comment either overload to prevent crash and get correct error messages
  static void Set(int*) {}
  static void Set(double*) {}
};

Command:
clang push.cpp

Output:
push.cpp:18:5: error: use of undeclared identifier 'Set'
    Set(x);
    ^
    this->
push.cpp:3:5: note: in instantiation of function template specialization
      'A::Get<int>' requested here
    Get<>(x, x);
    ^

The fixit "this->"  for Set is not needed since the two Set functions are in
scope, and the various other calls to Set don't require it.  The crash happens
at:

lib/Sema/SemaExpr.cpp:
1839           else if (CurMethod->getTemplatedKind() ==
1840              FunctionDecl::TK_FunctionTemplateSpecialization)
1841            DepMethod =
cast<CXXMethodDecl>(CurMethod->getPrimaryTemplate()->
1842                getInstantiatedFromMemberTemplate()->getTemplatedDecl());

getTemplateDecl() returns a null pointer.  cast<CXXMethodDecl> then crashes
when passed that null pointer.</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>