Skip to content

Commit 04cbc86

Browse files
committed
[clang] check deduction consistency when partial ordering function templates
This makes partial ordering of function templates consistent with other entities. Fixes #18291
1 parent 70a9535 commit 04cbc86

File tree

11 files changed

+420
-244
lines changed

11 files changed

+420
-244
lines changed

clang-tools-extra/test/clang-tidy/checkers/bugprone/stringview-nullptr.cpp

Lines changed: 8 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t
1+
// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++20 %t
22

33
namespace std {
44

@@ -30,98 +30,27 @@ class basic_string_view {
3030
constexpr basic_string_view &operator=(const basic_string_view &) {}
3131
};
3232

33-
template <typename CharT>
34-
constexpr bool operator<(basic_string_view<CharT>, basic_string_view<CharT>) {
35-
return {};
36-
}
37-
template <typename CharT>
38-
constexpr bool operator<(type_identity_t<basic_string_view<CharT>>,
39-
basic_string_view<CharT>) {
40-
return {};
41-
}
42-
template <typename CharT>
43-
constexpr bool operator<(basic_string_view<CharT>,
44-
type_identity_t<basic_string_view<CharT>>) {
45-
return {};
46-
}
47-
48-
template <typename CharT>
49-
constexpr bool operator<=(basic_string_view<CharT>, basic_string_view<CharT>) {
50-
return {};
51-
}
52-
template <typename CharT>
53-
constexpr bool operator<=(type_identity_t<basic_string_view<CharT>>,
54-
basic_string_view<CharT>) {
55-
return {};
56-
}
57-
template <typename CharT>
58-
constexpr bool operator<=(basic_string_view<CharT>,
59-
type_identity_t<basic_string_view<CharT>>) {
60-
return {};
61-
}
62-
63-
template <typename CharT>
64-
constexpr bool operator>(basic_string_view<CharT>, basic_string_view<CharT>) {
65-
return {};
66-
}
67-
template <typename CharT>
68-
constexpr bool operator>(type_identity_t<basic_string_view<CharT>>,
69-
basic_string_view<CharT>) {
70-
return {};
71-
}
72-
template <typename CharT>
73-
constexpr bool operator>(basic_string_view<CharT>,
74-
type_identity_t<basic_string_view<CharT>>) {
75-
return {};
76-
}
77-
78-
template <typename CharT>
79-
constexpr bool operator>=(basic_string_view<CharT>, basic_string_view<CharT>) {
80-
return {};
81-
}
82-
template <typename CharT>
83-
constexpr bool operator>=(type_identity_t<basic_string_view<CharT>>,
84-
basic_string_view<CharT>) {
85-
return {};
86-
}
87-
template <typename CharT>
88-
constexpr bool operator>=(basic_string_view<CharT>,
89-
type_identity_t<basic_string_view<CharT>>) {
90-
return {};
91-
}
33+
using string_view = basic_string_view<char>;
9234

93-
template <typename CharT>
94-
constexpr bool operator==(basic_string_view<CharT>, basic_string_view<CharT>) {
35+
constexpr bool operator<(string_view, string_view) {
9536
return {};
9637
}
97-
template <typename CharT>
98-
constexpr bool operator==(type_identity_t<basic_string_view<CharT>>,
99-
basic_string_view<CharT>) {
38+
constexpr bool operator<=(string_view, string_view) {
10039
return {};
10140
}
102-
template <typename CharT>
103-
constexpr bool operator==(basic_string_view<CharT>,
104-
type_identity_t<basic_string_view<CharT>>) {
41+
constexpr bool operator>(string_view, string_view) {
10542
return {};
10643
}
107-
108-
template <typename CharT>
109-
constexpr bool operator!=(basic_string_view<CharT>, basic_string_view<CharT>) {
44+
constexpr bool operator>=(string_view, string_view) {
11045
return {};
11146
}
112-
template <typename CharT>
113-
constexpr bool operator!=(type_identity_t<basic_string_view<CharT>>,
114-
basic_string_view<CharT>) {
47+
constexpr bool operator==(string_view, string_view) {
11548
return {};
11649
}
117-
template <typename CharT>
118-
constexpr bool operator!=(basic_string_view<CharT>,
119-
type_identity_t<basic_string_view<CharT>>) {
50+
constexpr bool operator!=(string_view, string_view) {
12051
return {};
12152
}
12253

123-
using string_view = basic_string_view<char>;
124-
12554
} // namespace std
12655

12756
using SV = std::string_view; // Used in some places for shorter line length

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ Bug Fixes to C++ Support
153153

154154
- Fixed a crash when an expression with a dependent ``__typeof__`` type is used as the operand of a unary operator. (#GH97646)
155155
- Fixed a failed assertion when checking invalid delete operator declaration. (#GH96191)
156+
- When performing partial ordering of function templates, clang now checks that
157+
the deduction was consistent. Fixes (#GH18291).
156158

157159
Bug Fixes to AST Handling
158160
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/ExprConstant.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5346,7 +5346,6 @@ static EvalStmtResult EvaluateStmt(StmtResult &Result, EvalInfo &Info,
53465346
const Expr *RetExpr = cast<ReturnStmt>(S)->getRetValue();
53475347
FullExpressionRAII Scope(Info);
53485348
if (RetExpr && RetExpr->isValueDependent()) {
5349-
EvaluateDependentExpr(RetExpr, Info);
53505349
// We know we returned, but we don't know what the value is.
53515350
return ESR_Failed;
53525351
}

0 commit comments

Comments
 (0)