- 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" #include <iostream> 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.
#pragma once MACRO_FROM_MISSING_INCLUDE("X") namespace my_namespace { //... }
Before this patch, my_namespace is not visible for auto-completion.
It'd help to update the comment below since it doesn't mention why namespaces are handled specially.