llvm-project/clang/test/Parser/gh30908-scope-balance-on-invalid-var-direct-init-1.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

21 lines
601 B
C++

// RUN: %clang_cc1 -ferror-limit 2 -fsyntax-only -verify %s
// expected-error@* {{too many errors emitted}}
namespace llvm {
namespace Hexagon {}
}
void set() {
Hexagon::NoRegister;
// expected-error@-1 {{use of undeclared identifier}}
// expected-note@-5 {{declared here}}
// expected-error@-3 {{no member named 'NoRegister' in namespace}}
}
template <class> struct pair { pair(int, int); };
struct HexagonMCChecker {
static pair<int> Unconditional;
void checkRegisters();
};
pair<int> HexagonMCChecker::Unconditional(Hexagon::NoRegister, 0);
void HexagonMCChecker::checkRegisters() {}