1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-20 23:45:23 +02:00

Scan for more template-id alternatives in expression, bug 497931

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
This commit is contained in:
Igor V. Kovalenko 2023-02-22 08:27:25 +03:00 committed by Jonah Graham
parent 2d3ab58e0b
commit 57a32fc521

View file

@ -150,8 +150,8 @@ public class NameOrTemplateIDVariants {
public Variant selectFallback() { public Variant selectFallback() {
// Search for an open variant, with a small right offset and a large left offset // 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()) { for (BranchPoint p = fFirst; p != null; p = p.getNext()) {
Variant best = null;
for (Variant v = p.getFirstVariant(); v != null; v = v.getNext()) { for (Variant v = p.getFirstVariant(); v != null; v = v.getNext()) {
if (v.getTargetOperator() == null) { if (v.getTargetOperator() == null) {
if (best == null || v.fRightOffset < best.fRightOffset) { if (best == null || v.fRightOffset < best.fRightOffset) {
@ -159,10 +159,10 @@ public class NameOrTemplateIDVariants {
} }
} }
} }
if (best != null) { }
remove(best); if (best != null) {
return best; remove(best);
} return best;
} }
return null; return null;
} }