bloomberg / clang-p2996

Experimental clang support for WG21 P2996 (Reflection).
https://github.com/bloomberg/clang-p2996/tree/p2996/P2996.md
51 stars 8 forks source link

Lookups don't always give precedence to nearer scopes #73

Closed katzdm closed 1 month ago

katzdm commented 1 month ago

The expression ^operand is parsed through a sequence of tentative parses, which terminates when one succeeds (or else fails):

  1. First, try parsing as a template
  2. Otherwise, try parsing as a namespace
  3. Otherwise, try parsing as a type-id
  4. Otherwise, try parsing as an expression

We inherited this model from the old Lock3 implementation of P1240. It has so far served well, but as pointed out by Wyatt Childers, it does the wrong thing in cases like the following (godbolt):

namespace foo {
struct foo {
    static_assert(is_type(^foo));  // static assertion failed ...
};
}  // namespace foo

We should try to rewrite this to leverage a single unqualified lookup rather than a sequence of tentative parses.