[clang] [Clang] Reapply CWG2369 "Ordering between constraints and substitution" (PR #122423)

Jordan Rupprecht via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 5 18:38:32 PDT 2025


rupprecht wrote:

I bisected a build failure to this commit. I can't figure out if it's expected or not. I minimized it to this:

```c++
#include <concepts>

enum class KindEnum {
    Unknown = 0,
    Foo = 1,
};

template <typename T>
concept KnownKind = T::kind() != KindEnum::Unknown;

template <KnownKind T>
struct KnownType;

struct Type {
    KindEnum kind() const;

    static Type f(Type t);

    template <KnownKind T>
    static KnownType<T> f(T t);

    static void g() {
        Type t;
        f(t);
    }
};

template <KnownKind T>
struct KnownType {
    static constexpr KindEnum kind() { return KindEnum::Foo; }
};
```

gcc accepts it. After this commit, clang rejects it:
```
<source>:9:21: error: substitution into constraint expression resulted in a non-constant expression
    9 | concept KnownKind = T::kind() != KindEnum::Unknown;
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:19:15: note: while checking the satisfaction of concept 'KnownKind<Type>' requested here
   19 |     template <KnownKind T>
      |               ^
<source>:19:15: note: while substituting template arguments into constraint expression here
   19 |     template <KnownKind T>
      |               ^~~~~~~~~
<source>:24:9: note: while checking constraint satisfaction for template 'f<Type>' required here
   24 |         f(t);
      |         ^
<source>:24:9: note: while substituting deduced template arguments into function template 'f' [with T = Type]
<source>:9:24: note: implicit use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function
    9 | concept KnownKind = T::kind() != KindEnum::Unknown;
      |                        ^
1 error generated.
```

Live link: https://godbolt.org/z/oGh319a44

Is this sort of breakage expected?

https://github.com/llvm/llvm-project/pull/122423


More information about the cfe-commits mailing list