[all-commits] [llvm/llvm-project] 0c7d46: [Clang] Correctly construct template arguments for...

Younan Zhang via All-commits all-commits at lists.llvm.org
Sat Jan 6 06:26:48 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0c7d46a7fd5b7956e285d385a6945153d6a06eb0
      https://github.com/llvm/llvm-project/commit/0c7d46a7fd5b7956e285d385a6945153d6a06eb0
  Author: Younan Zhang <zyn7109 at gmail.com>
  Date:   2024-01-06 (Sat, 06 Jan 2024)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/Sema/SemaTemplateInstantiate.cpp
    M clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp

  Log Message:
  -----------
  [Clang] Correctly construct template arguments for template template parameters (#76811)

This fixes the bug introduced by

https://github.com/llvm/llvm-project/commit/6db007a0654ed7a6ed5c3aa3b61a937c19a6bc6b.

We construct placeholder template arguments for template-template
parameters to avoid mismatching argument substitution since they have
different depths with their corresponding template arguments. In this
case,

```cpp
template <template <Concept C> class T> void foo(T<int>);
```

T lies at the depth 0, and C lies at 1. The corresponding argument, of
which there is exactly one, int, is at depth 0. If we consider the
argument as the outermost one, then we would end up substituting 'int'
into the wrong parameter T.

We used to perform such placeholder construction during the context
walk-up. In the previous patch, we slipped through that inadvertently
because we would walk up to the parent, which is precisely a FileContext
for template-template parameters, after adding innermost arguments.

Besides, this patch moves the sanity check up to the context switch.
That way, we avoid dereferencing null pointers if ND is unspecified.

Closes https://github.com/llvm/llvm-project/issues/57410.
Closes https://github.com/llvm/llvm-project/issues/76604. (The case is
slightly different than that in #57410. We should *not* assume the
surrounding context to be a file-scope one.)




More information about the All-commits mailing list