[all-commits] [llvm/llvm-project] 6f9231: [Clang][P1061] Fix template arguments in local cla...

Jason Rice via All-commits all-commits at lists.llvm.org
Sat Jul 12 20:18:03 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6f923134ddf4afc4266c4c32854d7cc2793c23a1
      https://github.com/llvm/llvm-project/commit/6f923134ddf4afc4266c4c32854d7cc2793c23a1
  Author: Jason Rice <ricejasonf at gmail.com>
  Date:   2025-07-13 (Sun, 13 Jul 2025)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/Sema/SemaTemplateInstantiate.cpp
    A clang/test/SemaCXX/local-class-template-param-crash.cpp

  Log Message:
  -----------
  [Clang][P1061] Fix template arguments in local classes (#121225)

In the development of P1061 (Structured Bindings Introduce a Patch), I
found this bug in the template instantiation of a
local class. The issue is caused by the instantiation of the original
template and not the partially instantiated template. In
the example (sans the fix) the instantiation uses the first template
parameter from the previous instantiation and not the current one so the
error hits an assertion when it is expecting an NTTP. If they were both
types then it might gladly accept the type from the wrong template which
is kind of scary.

In the test, the reference to `i` is substituted with a placeholder AST
object that represents the resolved value when instantiating `g`.
However, since the old template is used, the instantiation sees an AST
object that only contains the template argument index in the context of
instantiating the lambda which has a type template parameter (ie auto).

I question if we should use `getTemplateInstantiationPattern` at all
here. Other errors involving local classes in nested templates could
also be caused by the misuse of this function (because it gets the
uninstantiated template).



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list