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: concept checking bug in out-of-line definitions of inner class member functions #65810

Closed
davidtgoldblatt opened this issue Sep 8, 2023 · 7 comments · Fixed by #65993
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts

Comments

@davidtgoldblatt
Copy link
Contributor

This code:

template<typename Param>
concept TrivialConcept =
  requires(Param param) {
    (void)param;
  };

template <typename T>
struct Base {
    class InnerClass;
};

template <typename T>
class Base<T>::InnerClass {
    template <typename Param>
    requires TrivialConcept<Param> 
    int func(Param param) const;
};

template <typename T>
template <typename Param>
requires TrivialConcept<Param>
int Base<T>::InnerClass::func(Param param) const {
    return 0;
}

Works on clang-16 and gcc trunk, fails on clang trunk. I believe it should be allowed per C++20 and above.

Bisecting points to 6db007a as the likely culprit (this got reverted a couple of times previously for similar issues; this one slipped past).

Tagging a few interested people from the diff and from #63782, which points to the same commit:
@alexander-shaposhnikov @erichkeane @shafik

@davidtgoldblatt davidtgoldblatt added c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts labels Sep 8, 2023
@github-actions github-actions bot added clang Clang issues not falling into any other category new issue labels Sep 8, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 8, 2023

@llvm/issue-subscribers-clang-frontend

@llvmbot
Copy link
Collaborator

llvmbot commented Sep 8, 2023

@llvm/issue-subscribers-c-20

@EugeneZelenko EugeneZelenko removed clang Clang issues not falling into any other category new issue labels Sep 8, 2023
@shafik
Copy link
Collaborator

shafik commented Sep 9, 2023

@erichkeane do you have any advice on what to do here?

@alexander-shaposhnikov
Copy link
Collaborator

I think it's a bug in Clang, we need to fix it.
p.s. unfortunately, bisecting to 6db007a is not of much help here (that commit switched the approach to how we compare constraints). The symptoms are similar to what we've seen before.

@erichkeane
Copy link
Collaborator

So this is another part of comparing constraints that I don't particularly well understand, all handled by AreConstraintExpressionsEqual. We end up needing to substitute each constraint expression with the details from the current declaration, however this is a case of the 'new' Expression not finding any levels to substitute, which seems incorrect to me? So I think the problem is in line 758's call to getTemplateInstantiationArgs.

@alexander-shaposhnikov 's 6db007a ends up adding this line, so I am concerned that the changes he made to the collection of arguments is at least partially to blame here, but I don't particularly have the ability to debug much more.

@erichkeane
Copy link
Collaborator

Actually, I think when 6db007a's HandleFunctionTemplateDecl is trying to find the template arguments, it ends up not handling it right. I suspect instead of the 'if' statement there, it should be 'looping' upwards through the NestedNameSpecifiers. In this case, it ends up finding JUST the InnerClass which doesn't add template arguments, but probably should ALSO loop up a step for Base<T>.

erichkeane added a commit to erichkeane/llvm-project that referenced this issue Sep 11, 2023
As reported in GH65810, we don't properly collect ALL of the template
parameters in a nested name specifier, and were only doing the 'inner
level'.

This patch makes sure we collect from all levels.

Fixes: llvm#65810
@erichkeane
Copy link
Collaborator

Bah, I got nerd-sniped. I have a patch up for review here: #65993

erichkeane added a commit that referenced this issue Sep 12, 2023
As reported in GH65810, we don't properly collect ALL of the template
parameters in a nested name specifier, and were only doing the 'inner
level'.

This patch makes sure we collect from all levels.

Fixes: #65810
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this issue Sep 19, 2023
As reported in GH65810, we don't properly collect ALL of the template
parameters in a nested name specifier, and were only doing the 'inner
level'.

This patch makes sure we collect from all levels.

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

Successfully merging a pull request may close this issue.

6 participants