Skip to content

Commit

Permalink
Scan for more template-id alternatives in expression, bug 497931
Browse files Browse the repository at this point in the history
If parsing expression part for an alternative terminates with BacktrackException,
selectFallback() would short-circuit to the longest remaining variant. If that
happens to successfully complete parsing till the end of expression token
sequence, all of remaining variants are discarded, including the first found
alternative which was to parse identifier as template name.

This causes expression() to only consider one branchpoint out of all possible
variants. Allow it to find more variants by scanning through all branchpoints
looking for the alternative with leftmost parsed boundary.

This is probably still not ideal but fixes this common std library construct:

  template <typename T>
  inline constexpr bool X = true;
  template <typename T>
  inline constexpr bool Y = true;

  template<typename T> bool predicate() {
    return X<T> && Y<T>; // CDT finds this one: (X) < (T) > (&&Y<T>)
                         // Fix it to also consider (X<T>) && (Y<T>)
  }

Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=497931
  • Loading branch information
i-garrison authored and jonahgraham committed Feb 27, 2023
1 parent 2d3ab58 commit 57a32fc
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,19 @@ public void closeVariants(int offset, BinaryOperator lastOperator) {

public Variant selectFallback() {
// Search for an open variant, with a small right offset and a large left offset
Variant best = null;
for (BranchPoint p = fFirst; p != null; p = p.getNext()) {
Variant best = null;
for (Variant v = p.getFirstVariant(); v != null; v = v.getNext()) {
if (v.getTargetOperator() == null) {
if (best == null || v.fRightOffset < best.fRightOffset) {
best = v;
}
}
}
if (best != null) {
remove(best);
return best;
}
}
if (best != null) {
remove(best);
return best;
}
return null;
}
Expand Down

0 comments on commit 57a32fc

Please sign in to comment.