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

An example code from the standard (templates and concepts) does not compile #50208

Closed
mmatrosov opened this issue Jun 25, 2021 · 6 comments
Closed
Labels
bugzilla Issues migrated from bugzilla c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts duplicate Resolved as duplicate

Comments

@mmatrosov
Copy link

mmatrosov commented Jun 25, 2021

Bugzilla Link 50864
Version trunk
OS Linux
CC @erichkeane,@zygoloid,@viccie30,@jwakely

Extended Description

According to [temp.constr.decl]/4 the following example should compile:

template <class T> concept C = true;
template <class T> struct A {
  template <class U> U f(U) requires C<typename T::type>;   // #1
  template <class U> U f(U) requires C<T>;                  // #2
};

template <> template <class U>
U A<int>::f(U u) requires C<int> { return u; }              // OK, specializes #2

However, clang gives an error:

<source>:3:49: error: type 'int' cannot be used prior to '::' because it has no members
  template <class U> U f(U) requires C<typename T::type>;   // #1
                                                ^

I believe this is the reason why clang cannot compile libstdc++ ranges: #46091

@erichkeane
Copy link
Collaborator

I'm almost positive this is a duplicate of #44178 #c4.

The problem here is that we're greedily evaluating concepts immediately upon instantiation of the class, rather than waiting until they are called.

@jwakely
Copy link
Mannequin

jwakely mannequin commented Nov 23, 2021

I'm almost positive this is a duplicate of
#44178 #c4.

Agreed. I was about to say that Bug 47509 (which links here) is a dup of that one.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@Quuxplusone Quuxplusone added the concepts C++20 concepts label Jan 16, 2022
@royjacobson
Copy link
Contributor

Still doesn't work after https://reviews.llvm.org/D126907 but I think it's a different bug now.

<source>:8:11: error: out-of-line definition of 'f' does not match any declaration in 'A<int>'
U A<int>::f(U u) requires C<int> { return u; }              // OK, specializes #2
          ^

@EugeneZelenko EugeneZelenko added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Sep 23, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 23, 2022

@llvm/issue-subscribers-clang-frontend

@royjacobson
Copy link
Contributor

Sema::isOverload compares the concepts of the definition to the uninstantiated constraints of the initial declaration, and they're differnt. So Sema::CheckOverload in Sema::CheckFunctionDeclaration thinks this is an overload and not a definition.

I think we need to instantiate the specialized struct and then do a lookup or something like that, I'm not sure how this is only a problem for constrained methods so I probably missed something.

@usx95
Copy link
Contributor

usx95 commented Oct 30, 2022

The left over bug is same as #49620.

@usx95 usx95 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 30, 2022
@EugeneZelenko EugeneZelenko added the duplicate Resolved as duplicate label Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts duplicate Resolved as duplicate
Projects
Status: Done
Development

No branches or pull requests

7 participants