New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature request] requires clause in class templates (Concepts TS) #31513
Comments
assigned to @HazardyKnusperkeks |
The STL2 formats requires clauses in some places like this: template <class T, class U, class... Rest> That is:
|
Poke, poke. Now that C++20 has been sent out for (what will likely be) its final round of balloting, it would be a good time to work on supporting requires-clauses in clang-format. Think of all the poor, suffering STL maintainers! |
In version 13 they have an IndentRequires that basically either indents or not. |
I'm working on it. |
mentioned in issue llvm/llvm-bugzilla-archive#52401 |
Review link: https://reviews.llvm.org/D113319 |
Pushed |
Extended Description
The following code:
template <class T, class U, class... Rest>
requires CommonReference<T, U>()
struct common_reference<T, U, Rest...>
: common_reference<common_reference_t<T, U>, Rest...> {};
is reformatted to
template <class T, class U, class... Rest>
requires CommonReference<T, U>() struct common_reference<T, U, Rest...>
: common_reference<common_reference_t<T, U>, Rest...> {};
because clang-format does not understand the requires keyword in class templates.
It should either be formatted to
// A: requires clause in its own line:
template <class T, class U, class... Rest>
requires CommonReference<T, U>()
struct common_reference<T, U, Rest...>
: common_reference<common_reference_t<T, U>, Rest...> {};
// B: small require clause in line with template arguments
template <class T, class U, class... Rest> requires CommonReference<T, U>()
struct common_reference<T, U, Rest...>
: common_reference<common_reference_t<T, U>, Rest...> {};
Also, long requires clauses are not handled properly
template <class T, class U, class... Rest>
requires CommonReference<T, U>() &&
CommonReference<T, U>() &&
CommonReference<T, U>()
struct common_reference<T, U, Rest...>
: common_reference<common_reference_t<T, U>, Rest...> {};
is reformatted to:
template <class T, class U, class... Rest>
requires CommonReference<T, U>() && CommonReference<T, U>() &&
CommonReference<T, U>() struct common_reference<T, U, Rest...>
: common_reference<common_reference_t<T, U>, Rest...> {};
Following customization parameters might make sense, but I haven't given this much thought:
And well probably stuff like BreakBeforeBinaryOperators should work here properly.
The text was updated successfully, but these errors were encountered: