Issue 239411
Summary [clang] C++26: type-constraint pack with a fold-based concept is checked against the wrong pack element
Labels clang
Assignees
Reporter Nemi26
    ```cpp
template<class T, class... U> concept _OneOf_ = (__is_same(T, U) || ...);
template<class P> concept Part = OneOf<P, short> || __is_same(P, int);
template<Part... Ps> int f(Ps...) { return 0; }
int x = f(1, short(2));
```
`clang++ -std=c++2c -fsyntax-only` rejects this. `-std=c++20` and `-std=c++23` accept it, and so does Clang 18 in every mode. Seen with Clang 23.1.6.
```
error: no matching function for call to 'f'
note: candidate template ignored: constraints not satisfied [with Ps = <int, short>]
note: because 'short' does not satisfy 'Part'
note: because 'OneOf<short, short>' evaluated to false
note: because '__is_same(int, short)' evaluated to false
```
`OneOf<short, short>` is reported false because `__is_same(int, short)` was evaluated: the first pack element's type (`int`) is substituted while checking the second element (`short`).
Swapping the arguments, `f(short(2), 1)`, compiles.
Replacing the fold in `OneOf` with a non-variadic `template<class T, class U> concept Same = __is_same(T, U);` (`Part = Same<P, short> || Same<P, int>`) compiles.
Possibly related to #199569 (fold-expanded constraints in C++26 mode, fixed for non-type template parameters in #210005) and #199545 (constraint canonicalization). This case involves type parameters only.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to