Skip to content

[Clang][concepts] Clang may fail to match the appropriate partial specialization if contrained by a requires expression containing lambdas #62516

Closed
@erinacio

Description

@erinacio

This issue is first found on clangd 17 shipped with CLion 2023.1.2 (22d9828), and reproduced on x86_64 clang trunk on compiler explorer (0a02f76) and clang-17 from apt.llvm.org (6875424).

This issue seems to only occur when:

  1. There's a class template (template <class T> struct A).
  2. There's a constrained partial specialization (template <C T> struct A<T>).
  3. That is effectively contrained by a requires expression (template <class T> concept C = requires ...;).
  4. That requires expression contains a lambda expression.
  5. That contraint is not tested before.

Given a type T which satisfies that constraint (i.e. static_assert(C<T>)), clang trunk will fail to match the partial specialization template <C T> struct A<T> if the constraint is not explicitly tested before (including static_assert(C<T>)), and any test to the constraint will fail afterwards.

MRE#1: https://godbolt.org/z/rEfP7PcPc, lambda used as a simple requirement.
MRE#2: https://godbolt.org/z/GhqdnqMGb, lambda used inside parameter list with decltype.

A slightly longer but more meaningful example: https://godbolt.org/z/xfGjrq7db.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 concepts

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions