Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[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