This is an archive of the discontinued LLVM Phabricator instance.

[pseudo] Eliminate a false parse of structured binding declaration.
ClosedPublic

Authored by hokein on Aug 19 2022, 1:01 PM.

Details

Summary

Using the guard to implement part of the rule https://eel.is/c++draft/dcl.pre#6.

void foo() {
  // can be parsed as
  //   - structured-binding declaration (a false parse)
  //   - assignment expression
  array[index] = value;
}

Diff Detail

Event Timeline

hokein created this revision.Aug 19 2022, 1:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 19 2022, 1:01 PM
hokein requested review of this revision.Aug 19 2022, 1:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 19 2022, 1:01 PM
sammccall accepted this revision.Aug 22 2022, 7:38 AM
sammccall added inline comments.
clang-tools-extra/pseudo/lib/cxx/CXX.cpp
164

nit: specifiesStructuredBinding?
(because the structured binding itself is something bigger)

166

If you're going to iterate over tokens, it seems more direct (and cheaper) to do it directly:
for (const Tok& : P.Tokens.tokens(RHS[0].startTokenIndex(), RHS[1].startTokenIndex()))

clang-tools-extra/pseudo/test/cxx/structured-binding.cpp
2

nit: drop blank line

This revision is now accepted and ready to land.Aug 22 2022, 7:38 AM
hokein updated this revision to Diff 454816.Aug 23 2022, 6:24 AM
hokein marked 3 inline comments as done.

address comments

This revision was landed with ongoing or failed builds.Aug 23 2022, 6:26 AM
This revision was automatically updated to reflect the committed changes.