
* 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
22 lines
555 B
C++
22 lines
555 B
C++
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
|
|
|
UNKNOWN_MACRO_1("z", 1) // expected-error {{a type specifier is required for all declarations}}
|
|
// expected-error@-1 {{expected ';' after top level declarator}}
|
|
|
|
namespace foo {
|
|
class bar {};
|
|
}
|
|
|
|
int variable = 0; // ok
|
|
foo::bar something; // ok
|
|
|
|
UNKNOWN_MACRO_2(void) // expected-error {{a type specifier is required for all declarations}}
|
|
// expected-error@-1 {{expected ';' after top level declarator}}
|
|
|
|
namespace baz {
|
|
using Bool = bool;
|
|
}
|
|
|
|
int variable2 = 2; // ok
|
|
const baz::Bool flag = false; // ok
|