1// RUN: rm -rf %t
2// RUN: mkdir %t
3// RUN: split-file %s %t
4//
5// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
6// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -I%t -DDIFFERENT %t/B.cppm -verify
7// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -I%t %t/B.cppm -verify
8
9//--- foo.h
10#ifndef FOO_H
11#define FOO_H
12
13template <class T>
14concept Range = requires(T &t) { t.begin(); };
15
16template<class _Tp>
17concept __integer_like = true;
18
19template <class _Tp>
20concept __member_size = requires(_Tp &&t) { t.size(); };
21
22template <class First, class Second>
23concept C = requires(First x, Second y) { x + y; };
24
25struct A {
26public:
27  template <Range T>
28  using range_type = T;
29};
30
31struct __fn {
32  template <__member_size _Tp>
33  constexpr __integer_like auto operator()(_Tp&& __t) const {
34    return __t.size();
35  }
36
37  template <__integer_like _Tp, C<_Tp> Sentinel>
38  constexpr _Tp operator()(_Tp &&__t, Sentinel &&last) const {
39    return __t;
40  }
41
42  template <template <class> class H, class S, C<H<S>> Sentinel>
43  constexpr H<S> operator()(H<S> &&__s, Sentinel &&last) const {
44    return __s;
45  }
46
47// Tests that we could find different concept definition indeed.
48#ifndef DIFFERENT
49  template <__integer_like _Tp, __integer_like _Up, C<_Tp> Sentinel>
50  constexpr _Tp operator()(_Tp &&__t, _Up _u, Sentinel &&last) const {
51    return __t;
52  }
53#else
54  template <__integer_like _Tp, __integer_like _Up, C<_Up> Sentinel>
55  constexpr _Tp operator()(_Tp &&__t, _Up _u, Sentinel &&last) const {
56    return __t;
57  }
58#endif
59};
60#endif
61
62//--- A.cppm
63module;
64#include "foo.h"
65export module A;
66
67//--- B.cppm
68module;
69#include "foo.h"
70export module B;
71import A;
72
73#ifdef DIFFERENT
74// [email protected]:41 {{'__fn::operator()' from module 'A.<global>' is not present in definition of '__fn' provided earlier}}
75// expected-note@* 1+{{declaration of 'operator()' does not match}}
76#else
77// expected-no-diagnostics
78#endif
79
80template <class T>
81struct U {
82  auto operator+(U) { return 0; }
83};
84
85void foo() {
86    A a;
87    struct S {
88        int size() { return 0; }
89        auto operator+(S s) { return 0; }
90    };
91    __fn{}(S());
92    __fn{}(S(), S());
93    __fn{}(S(), S(), S());
94
95    __fn{}(U<int>(), U<int>());
96}
97