Skip to content

Commit 5e01234

Browse files
author
Erich Keane
committed
Add a new modules test to ensure we dont rebreak diagnostic
Fixes: 60336 Seemingly the concepts sugaring patch caused us to not catch this situation, which has been confirmed to be a valid error. Make sure that we catch this situation in the future, particularly if the concepts sugaring patch gets re added.
1 parent 09ba324 commit 5e01234

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

clang/test/Modules/GH60336.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// RUN: rm -rf %t
2+
// RUN: %clang_cc1 -x c++ -std=c++20 %s -verify -fmodules -fmodules-cache-path=%t
3+
#pragma clang module build std
4+
module std [system] {
5+
module concepts [system] {
6+
module assignable [system] {
7+
}
8+
export *
9+
}
10+
module functional [system] {
11+
export *
12+
}
13+
14+
15+
module type_traits [system] {
16+
export *
17+
}
18+
}
19+
20+
#pragma clang module contents
21+
#pragma clang module begin std.type_traits
22+
namespace std {
23+
template<class _Tp, class _Up>
24+
concept same_as = __is_same(_Tp, _Up);
25+
26+
template <class...>
27+
struct common_reference;
28+
29+
template <class _Tp, class _Up> struct common_reference<_Tp, _Up>
30+
{
31+
using type = _Tp;
32+
};
33+
}
34+
#pragma clang module end // type_traits
35+
36+
#pragma clang module begin std.concepts.assignable
37+
#pragma clang module import std.type_traits
38+
namespace std {
39+
template<class _Tp, class _Up>
40+
concept common_reference_with =
41+
same_as<typename common_reference<_Tp, _Up>::type, typename common_reference<_Up, _Tp>::type>;
42+
}
43+
namespace std {
44+
template<class _Lhs, class _Rhs>
45+
concept assignable_from =
46+
common_reference_with<const __remove_reference_t(_Lhs)&, const __remove_reference_t(_Rhs)&> ;
47+
}
48+
#pragma clang module end // std.concepts.assignable
49+
50+
#pragma clang module begin std.functional
51+
#pragma clang module import std.concepts.assignable
52+
namespace std {
53+
template<class _Sp, class _Ip>
54+
concept sentinel_for = assignable_from<_Ip&, _Ip>;
55+
template <class _Sp, class _Ip>
56+
concept nothrow_sentinel_for = sentinel_for<_Sp, _Ip>;
57+
}
58+
#pragma clang module end // std::functional
59+
#pragma clang module endbuild // contents
60+
61+
62+
#pragma clang module import std.functional
63+
constexpr bool ntsf_subsumes_sf(std::nothrow_sentinel_for<char*> auto) requires true {
64+
return true;
65+
}
66+
constexpr bool ntsf_subsumes_sf(std::sentinel_for<char*> auto);
67+
static_assert(ntsf_subsumes_sf("foo"));
68+
69+
// Note: Doing diagnostics verify lines in the individual modules isn't
70+
// permitted, and using 'bookmarks' in a module also doesn't work, so we're
71+
// forced to diagnose this by line-number.
72+
//
73+
// Check to ensure that this error happens, prior to a revert of a concepts
74+
// sugaring patch, this diagnostic didn't happen correctly.
75+
76+
// expected-error@* {{partial specialization of 'common_reference<_Tp, _Up>' must be imported from module 'std.type_traits' before it is required}}
77+
// expected-note@63 {{while substituting into concept arguments here}}
78+
// expected-note@*{{partial specialization declared here is not reachable}}

0 commit comments

Comments
 (0)