[all-commits] [llvm/llvm-project] 90786a: [Clang][Sema] Always use latest redeclaration of p...

Krystian Stasiowski via All-commits all-commits at lists.llvm.org
Wed Oct 30 11:51:01 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 90786adade22784a52856a0e8b545ec6710b47f6
      https://github.com/llvm/llvm-project/commit/90786adade22784a52856a0e8b545ec6710b47f6
  Author: Krystian Stasiowski <sdkrystian at gmail.com>
  Date:   2024-10-30 (Wed, 30 Oct 2024)

  Changed paths:
    M clang/include/clang/AST/DeclTemplate.h
    M clang/lib/AST/Decl.cpp
    M clang/lib/AST/DeclCXX.cpp
    M clang/lib/AST/DeclTemplate.cpp
    M clang/lib/Sema/SemaDecl.cpp
    M clang/lib/Sema/SemaInit.cpp
    M clang/lib/Sema/SemaTemplateInstantiate.cpp
    M clang/test/AST/ast-dump-decl.cpp
    M clang/test/CXX/temp/temp.spec/temp.expl.spec/p7.cpp

  Log Message:
  -----------
  [Clang][Sema] Always use latest redeclaration of primary template (#114258)

This patch fixes a couple of regressions introduced in #111852.

Consider:

```
template<typename T>
struct A
{
    template<bool U>
    static constexpr bool f() requires U
    {
        return true;
    }
};

template<>
template<bool U>
constexpr bool A<short>::f() requires U
{
    return A<long>::f<U>();
}

template<>
template<bool U>
constexpr bool A<long>::f() requires U
{
    return true;
}

static_assert(A<short>::f<true>()); // crash here
```

This crashes because when collecting template arguments from the _first_
declaration of `A<long>::f<true>` for constraint checking, we don't add
the template arguments from the enclosing class template specialization
because there exists another redeclaration that is a member
specialization.

This also fixes the following example, which happens for a similar
reason:
```
// input.cppm

export module input;

export template<int N>
constexpr int f();

template<int N>
struct A {
  template<int J>
  friend constexpr int f();
};

template struct A<0>;

template<int N>
constexpr int f() {
  return N;
}
```

```
// input.cpp

import input;

static_assert(f<1>() == 1); // error: static assertion failed
```



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