[all-commits] [llvm/llvm-project] b32173: [clang][parser] Fix namespace dropping after malfo...

Alejandro Álvarez Ayllón via All-commits all-commits at lists.llvm.org
Mon May 15 04:41:32 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b321738f71259d138c9b2002944eb65f099ec2a6
      https://github.com/llvm/llvm-project/commit/b321738f71259d138c9b2002944eb65f099ec2a6
  Author: Alejandro Álvarez Ayllón <alejandro.alvarez at sonarsource.com>
  Date:   2023-05-15 (Mon, 15 May 2023)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/Parse/ParseDecl.cpp
    M clang/lib/Parse/ParseTemplate.cpp
    A clang/test/Parser/cxx-namespace-after-missing-semicolon.cpp
    A clang/test/Parser/cxx-template-recovery.cpp

  Log Message:
  -----------
  [clang][parser] Fix namespace dropping after malformed declarations

* After a malformed top-level declaration
* After a malformed templated class method declaration

In both cases, when there is a malformed declaration, any following
namespace is dropped from the AST. This can trigger a cascade of
confusing diagnostics that may hide the original error. An example:
```
// Start #include "SomeFile.h"
template <class T>
void Foo<T>::Bar(void* aRawPtr) {
    (void)(aRawPtr);
}
// End #include "SomeFile.h"

int main() {}
```
We get the original error, plus 19 others from the standard library.
With this patch, we only get the original error.

clangd can also benefit from this patch, as namespaces following the
malformed declaration is now preserved. i.e.
```

MACRO_FROM_MISSING_INCLUDE("X")

namespace my_namespace {
    //...
}
```
Before this patch, my_namespace is not visible for auto-completion.

Differential Revision: https://reviews.llvm.org/D150258




More information about the All-commits mailing list