[all-commits] [llvm/llvm-project] eb08c0: [Clang][Sema] Fix explicit specializations of memb...

Krystian Stasiowski via All-commits all-commits at lists.llvm.org
Tue Apr 2 05:36:04 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: eb08c0f1659d12524f58a01bf174177b8acedf2e
      https://github.com/llvm/llvm-project/commit/eb08c0f1659d12524f58a01bf174177b8acedf2e
  Author: Krystian Stasiowski <sdkrystian at gmail.com>
  Date:   2024-04-02 (Tue, 02 Apr 2024)

  Changed paths:
    M clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp
    M clang/docs/ReleaseNotes.rst
    M clang/lib/Sema/SemaDecl.cpp
    M clang/test/SemaCXX/deduced-return-type-cxx14.cpp

  Log Message:
  -----------
  [Clang][Sema] Fix explicit specializations of member function templates with a deduced return type (#86817)

Clang erroneously rejects the following:
```
template<typename T>
struct A
{
    template<typename U>
    auto f();
};

template<>
template<typename U>
auto A<int>::f(); // error: conflicting types for 'f'
```
This happens because the explicit specialization of `f` has its return
type replaced with a dependent `AutoType` in `ActOnFunctionDeclarator`,
but no such replacement occurs for the implicitly instantiated function
template `A<int>::f`. Since the return types don't match, the explicit
specialization is diagnosed as an invalid redeclaration.

This patch moves the replacement of the return type to
`CheckFunctionDeclaration` so it also happens during instantiation.
`setObjectOfFriendDecl` will have been called by then, so the `isFriend
&& CurContext->isDependentContext()` condition is made redundant &
removed (as it already happens in `DeclContext::isDependentContext`).
`Sema::IsOverload` only checks the _declared_ return type (which isn't
changed by the adjustment), so adjusting the return type afterwards
should be safe.



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