Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang trunk does not compile overloaded member functions with ref-qualifier #76358

Closed
forworldm opened this issue Dec 25, 2023 · 7 comments · Fixed by #77323
Closed

clang trunk does not compile overloaded member functions with ref-qualifier #76358

forworldm opened this issue Dec 25, 2023 · 7 comments · Fixed by #77323
Labels
c++23 clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@forworldm
Copy link

struct C {
    template<int> void f() && {}
    template<typename T> void f() const {}
};
<source>:3:31: error: cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&&'
    3 |     template<typename T> void f() const {}
      |                               ^
<source>:2:24: note: previous declaration is here
    2 |     template<int> void f() && {}
      |                        ^
1 error generated.
Compiler returned: 1

see https://godbolt.org/z/Kv83s6oY3

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Dec 25, 2023
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed clang Clang issues not falling into any other category labels Dec 25, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 25, 2023

@llvm/issue-subscribers-clang-frontend

Author: forworldm (forworldm)

```c++ struct C { template<int> void f() && {} template<typename T> void f() const {} }; ``` ``` <source>:3:31: error: cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&&' 3 | template<typename T> void f() const {} | ^ <source>:2:24: note: previous declaration is here 2 | template<int> void f() && {} | ^ 1 error generated. Compiler returned: 1 ```

see https://godbolt.org/z/Kv83s6oY3

@DimitryAndric
Copy link
Collaborator

This regressed as a side effect of llvmorg-18-init-07480-gaf47517 ("[C++] Implement "Deducing this" (P0847R7)") by @cor3ntin (cc @AaronBallman).

I think it should still accept the construction used here? It always worked in the past, and appears to break even compilation of older llvm versions!

@DimitryAndric
Copy link
Collaborator

Specifically, it seems to be caused by the moving of the block in IsOverloadOrOverrideImpl at https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaOverload.cpp#L1346, that has:

// If the function is a class member, its signature includes the
// cv-qualifiers (if any) and ref-qualifier (if any) on the function itself.

and emits err_ref_qualifier_overload in this case. The block used to be in Sema::IsOverload() and was subtly changed, I guess.

@cor3ntin
Copy link
Contributor

cor3ntin commented Jan 6, 2024

We should probably check the template parameter list before the check of signature as two functions with different template head are not overloads

@DimitryAndric
Copy link
Collaborator

How problematic is it to temporarily revert af47517, until this problem can be fixed? I'm encountering the cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&&' error in quite a few packages, for example SciPy (from https://scipy.org/).

@cor3ntin
Copy link
Contributor

cor3ntin commented Jan 8, 2024

Pretty problematic and disruptive given the fix should be easy... I'll get on it...

cor3ntin added a commit to cor3ntin/llvm-project that referenced this issue Jan 8, 2024
Functions which correspond but have different template parameter
lists are not redeclarations.

Fixes a regression introduced by af4751

(The patch just moves the template parameters check above if the
signature check)

Fixes llvm#76358
cor3ntin added a commit that referenced this issue Jan 8, 2024
Functions which correspond but have different template parameter lists
are not redeclarations.

Fixes a regression introduced by af4751

(The patch just moves the template parameters check above if the
signature check)

Fixes #76358
@DimitryAndric
Copy link
Collaborator

Thanks, that seems to work fine!

justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this issue Jan 28, 2024
Functions which correspond but have different template parameter lists
are not redeclarations.

Fixes a regression introduced by af4751

(The patch just moves the template parameters check above if the
signature check)

Fixes llvm#76358
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++23 clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants