This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Disallow decltype in the middle of constraints
ClosedPublic

Authored by rymiel on Dec 19 2022, 9:14 AM.

Details

Summary

If a function with a requires clause as a constraint has a decltype
return type, such as decltype(auto), the decltype was seen to be part
of the constraint clause, rather than as part of the function
declaration, causing it to be placed on the wrong line.

This patch disallows decltype to be a part of these clauses

Fixes https://github.com/llvm/llvm-project/issues/59578

Depends on D140339

Diff Detail

Event Timeline

rymiel created this revision.Dec 19 2022, 9:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 19 2022, 9:14 AM
rymiel requested review of this revision.Dec 19 2022, 9:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 19 2022, 9:14 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
rymiel added a project: Restricted Project.Dec 19 2022, 9:15 AM
HazardyKnusperkeks requested changes to this revision.Dec 19 2022, 1:23 PM
This revision now requires changes to proceed.Dec 19 2022, 1:23 PM

What if I make this depend on D140339? Then this change would no longer impact concept definitions.

What if I make this depend on D140339? Then this change would no longer impact concept definitions.

Yep, that would be right. It seems I can't put decltype directly in a requires clause.

clang/lib/Format/UnwrappedLineParser.cpp
3477–3478

The comment needs to be adapted.

But I think it could just be merged into the parsing of the requires clause, or not?

3477–3478

Actually this needs to be done on D140339.

rymiel marked an inline comment as done.Dec 22 2022, 4:04 PM
rymiel added inline comments.
clang/lib/Format/UnwrappedLineParser.cpp
3477–3478

You are right, thank you. D140339 will make it so parseConstraintExpression will only ever be called from parseRequiresClause. Should I do that refactor in D140339 or leave it for a future patch?

HazardyKnusperkeks added inline comments.
clang/lib/Format/UnwrappedLineParser.cpp
3477–3478

Either way.

This revision is now accepted and ready to land.Dec 23 2022, 5:46 AM
owenpan accepted this revision.Jan 2 2023, 1:14 AM
MyDeveloperDay accepted this revision.Jan 3 2023, 2:54 AM
This revision was landed with ongoing or failed builds.Jan 5 2023, 7:18 PM
This revision was automatically updated to reflect the committed changes.