[all-commits] [llvm/llvm-project] 708a9a: [Clang][Parse] Fix ambiguity with nested-name-spec...

Krystian Stasiowski via All-commits all-commits at lists.llvm.org
Mon Jul 29 11:01:21 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 708a9a06cba66bc8f739b05646e7d3be9247feee
      https://github.com/llvm/llvm-project/commit/708a9a06cba66bc8f739b05646e7d3be9247feee
  Author: Krystian Stasiowski <sdkrystian at gmail.com>
  Date:   2024-07-29 (Mon, 29 Jul 2024)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Lex/Preprocessor.h
    M clang/include/clang/Parse/Parser.h
    M clang/lib/Lex/PPCaching.cpp
    M clang/lib/Lex/Preprocessor.cpp
    M clang/lib/Parse/ParseCXXInlineMethods.cpp
    M clang/lib/Parse/ParseDecl.cpp
    M clang/lib/Parse/ParseExprCXX.cpp
    A clang/test/CXX/dcl.decl/dcl.meaning/dcl.mptr/p2.cpp
    M clang/test/CXX/temp/temp.res/p3.cpp

  Log Message:
  -----------
  [Clang][Parse] Fix ambiguity with nested-name-specifiers that may declarative (#96364)

Consider the following:
```
template<typename T>
struct A { };

template<typename T>
int A<T>::B::* f(); // error: no member named 'B' in 'A<T>'
```

Although this is clearly valid, clang rejects it because the
_nested-name-specifier_ `A<T>::` is parsed as-if it was declarative,
meaning, we parse it as-if it was the _nested-name-specifier_ in a
redeclaration/specialization. However, we don't (and can't) know whether
the _nested-name-specifier_ is declarative until we see the '`*`' token,
but at that point we have already complained that `A` has no member
named `B`! This patch addresses this bug by adding support for _fully_
unannotated _and_ unbounded tentative parsing, which allows for us to
parse past tokens without having to cache them until we reach a point
where we can guarantee to be past the construct we are disambiguating.

I don't know where the approach taken here is ideal -- alternatives are
welcome. However, the performance impact (as measured by
llvm-compile-time-tracker (https://llvm-compile-time-tracker.com/?config=Overview&stat=instructions%3Au&remote=sdkrystian)
is quite minimal (0.09%, which I plan to further improve).



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list