Skip to content

Commit

Permalink
[clang] check deduction consistency when partial ordering function te…
Browse files Browse the repository at this point in the history
…mplates

This makes partial ordering of function templates consistent with
other entities.

Fixes #18291
  • Loading branch information
mizvekov committed Jul 26, 2024
1 parent 70a9535 commit c7ef00e
Show file tree
Hide file tree
Showing 11 changed files with 419 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,98 +30,27 @@ class basic_string_view {
constexpr basic_string_view &operator=(const basic_string_view &) {}
};

template <typename CharT>
constexpr bool operator<(basic_string_view<CharT>, basic_string_view<CharT>) {
return {};
}
template <typename CharT>
constexpr bool operator<(type_identity_t<basic_string_view<CharT>>,
basic_string_view<CharT>) {
return {};
}
template <typename CharT>
constexpr bool operator<(basic_string_view<CharT>,
type_identity_t<basic_string_view<CharT>>) {
return {};
}

template <typename CharT>
constexpr bool operator<=(basic_string_view<CharT>, basic_string_view<CharT>) {
return {};
}
template <typename CharT>
constexpr bool operator<=(type_identity_t<basic_string_view<CharT>>,
basic_string_view<CharT>) {
return {};
}
template <typename CharT>
constexpr bool operator<=(basic_string_view<CharT>,
type_identity_t<basic_string_view<CharT>>) {
return {};
}

template <typename CharT>
constexpr bool operator>(basic_string_view<CharT>, basic_string_view<CharT>) {
return {};
}
template <typename CharT>
constexpr bool operator>(type_identity_t<basic_string_view<CharT>>,
basic_string_view<CharT>) {
return {};
}
template <typename CharT>
constexpr bool operator>(basic_string_view<CharT>,
type_identity_t<basic_string_view<CharT>>) {
return {};
}

template <typename CharT>
constexpr bool operator>=(basic_string_view<CharT>, basic_string_view<CharT>) {
return {};
}
template <typename CharT>
constexpr bool operator>=(type_identity_t<basic_string_view<CharT>>,
basic_string_view<CharT>) {
return {};
}
template <typename CharT>
constexpr bool operator>=(basic_string_view<CharT>,
type_identity_t<basic_string_view<CharT>>) {
return {};
}
using string_view = basic_string_view<char>;

template <typename CharT>
constexpr bool operator==(basic_string_view<CharT>, basic_string_view<CharT>) {
constexpr bool operator<(string_view, string_view) {
return {};
}
template <typename CharT>
constexpr bool operator==(type_identity_t<basic_string_view<CharT>>,
basic_string_view<CharT>) {
constexpr bool operator<=(string_view, string_view) {
return {};
}
template <typename CharT>
constexpr bool operator==(basic_string_view<CharT>,
type_identity_t<basic_string_view<CharT>>) {
constexpr bool operator>(string_view, string_view) {
return {};
}

template <typename CharT>
constexpr bool operator!=(basic_string_view<CharT>, basic_string_view<CharT>) {
constexpr bool operator>=(string_view, string_view) {
return {};
}
template <typename CharT>
constexpr bool operator!=(type_identity_t<basic_string_view<CharT>>,
basic_string_view<CharT>) {
constexpr bool operator==(string_view, string_view) {
return {};
}
template <typename CharT>
constexpr bool operator!=(basic_string_view<CharT>,
type_identity_t<basic_string_view<CharT>>) {
constexpr bool operator!=(string_view, string_view) {
return {};
}

using string_view = basic_string_view<char>;

} // namespace std

using SV = std::string_view; // Used in some places for shorter line length
Expand Down
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ Bug Fixes to C++ Support

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

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5346,7 +5346,6 @@ static EvalStmtResult EvaluateStmt(StmtResult &Result, EvalInfo &Info,
const Expr *RetExpr = cast<ReturnStmt>(S)->getRetValue();
FullExpressionRAII Scope(Info);
if (RetExpr && RetExpr->isValueDependent()) {
EvaluateDependentExpr(RetExpr, Info);
// We know we returned, but we don't know what the value is.
return ESR_Failed;
}
Expand Down
Loading

0 comments on commit c7ef00e

Please sign in to comment.