Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Does ambiguity resolution do unnecessary work?

I can only give the ancient history behind it, not having followed closely how things have evolved. But I think you've hit it. In order to pick the right one, everything is resolved. We tried hard to not do that, but it seemed the best way at the time. If there are cases where we can determine the correct path without resolving everything, go for it.

I wonder how Clang does it...

Doug.

From: cdt-dev-bounces@xxxxxxxxxxx [cdt-dev-bounces@xxxxxxxxxxx] on behalf of Sergey Prigogin [eclipse.sprigogin@xxxxxxxxx]
Sent: Tuesday, March 25, 2014 11:29 PM
To: CDT General developers list.
Subject: [cdt-dev] Does ambiguity resolution do unnecessary work?

I've noticed that during ambiguity resolution in the following code CDT parser tries to resolve bindings that should not be necessary for ambiguity resolution.
template<class T>
struct A {};

template <typename U>
A<int> waldo(U p);

void test() {
  typedef int INT;
  A<INT> latest = waldo([](int data) { return false; });
}
The statement
  A<INT> latest = waldo([](int data) { return false; });
contains an ambiguity between CPPASTDeclarationStatement and CPPASTExpressionStatement. This ambiguity is currently resolved by counting problems in the whole statement and choosing the alternative that produces fewer problems. This means that the parser makes two attempts to resolve waldo, both for the declaration and for the _expression_ alternatives.  This looks excessive since absence of problems in the type specifier should be sufficient to conclude that the statement is a declaration. Name resolution in the initializer should not be necessary. Likewise, absence of problems in the first operand of the binary _expression_ contained in the _expression_ statement alternative should be sufficient to conclude that the statement is an _expression_.

Does anybody know why ambiguity resolution always tries to resolve all names under the ambiguous node?

-sergey


Back to the top