llvm-project/clang/test/Parser/gh30908-scope-balance-on-invalid-var-direct-init-2.cpp
Ding Fei 46944210eb
[clang][Parser] Pop scope prior VarDecl invalidating by invalid init (#77434)
Invalid (direct) initializer would invalid `VarDecl` so
`InitializerScopeRAII` cannot restore scope stack balance.

As with other kind of initializer, `InitializerScopeRAII::pop()` is
moved up before `Sema::ActOnInitializerError()` which invalidates the
`VarDecl`, so scope can be balanced and current `DeclContext` can be
restored.

Fixes #30908
2024-01-10 08:49:36 +08:00

23 lines
319 B
C++

// RUN: %clang_cc1 -fsyntax-only -verify %s
#include <non-exist-header> // expected-error {{file not found}}
class S {};
template <typename T>
class E {
public:
E(S* scope) {}
S &getS();
};
class Z {
private:
static E<Z> e;
static S& s();
};
E<Z> Z::e(&__UNKNOWN_ID__);
S& Z::s() { return Z::e.getS(); }