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

Incorrect constraint check with template friend function #90349

Closed
toddreed opened this issue Apr 27, 2024 · 4 comments · May be fixed by #90646
Closed

Incorrect constraint check with template friend function #90349

toddreed opened this issue Apr 27, 2024 · 4 comments · May be fixed by #90646
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@toddreed
Copy link

See https://godbolt.org/z/rTcabGbbh. This compiles with GCC 13.2, but with clang 18.1.0.

I’ve tried to reduce this to the smallest program that exhibits the bug, and AFAICT, it relates to a template friend function that has the same template arguments as its enclosing class, but the order of the template arguments are reversed. When instantiating the template function, the compiler seems to apply the wrong constraint checks (C++ concepts) on the template arguments.

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Apr 27, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 27, 2024

@llvm/issue-subscribers-clang-frontend

Author: Todd Reed (toddreed)

See https://godbolt.org/z/rTcabGbbh. This compiles with GCC 13.2, but with clang 18.1.0.

I’ve tried to reduce this to the smallest program that exhibits the bug, and AFAICT, it relates to a template friend function that has the same template arguments as its enclosing class, but the order of the template arguments are reversed. When instantiating the template function, the compiler seems to apply the wrong constraint checks (C++ concepts) on the template arguments.

@shafik
Copy link
Collaborator

shafik commented Apr 29, 2024

Code: https://godbolt.org/z/qnh6EdGGe

Looks like only clang rejects.

#include <concepts>

template<std::integral T, std::floating_point Float>
class Blob;

template<std::floating_point Float, std::integral T>
Blob<T, Float> MakeBlob();

template<std::integral T, std::floating_point Float>
class Blob {
private:
    Blob() {}

    friend Blob<T, Float> MakeBlob<Float, T>();
};

template<std::floating_point Float, std::integral T>
Blob<T, Float> MakeBlob()
{
    return Blob<T, Float>();
}

template<std::floating_point Float, std::integral T>
Blob<T, Float> FindBlobs()
{
    return MakeBlob<Float, T>();
}

int main(int argc, const char * argv[]) {
    FindBlobs<double, int>();
    return 0;
}

CC @erichkeane @Fznamznon

@shafik shafik added the c++20 label Apr 29, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 29, 2024

@llvm/issue-subscribers-c-20

Author: Todd Reed (toddreed)

See https://godbolt.org/z/rTcabGbbh. This compiles with GCC 13.2, but with clang 18.1.0.

I’ve tried to reduce this to the smallest program that exhibits the bug, and AFAICT, it relates to a template friend function that has the same template arguments as its enclosing class, but the order of the template arguments are reversed. When instantiating the template function, the compiler seems to apply the wrong constraint checks (C++ concepts) on the template arguments.

@sdkrystian
Copy link
Member

Closed via #88963

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"
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants