|
@@ -2131,6 +2131,37 @@ Decl *Parser::ParseDeclarationAfterDeclarator(
|
|
|
|
|
|
Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
|
|
Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
|
|
Declarator &D, const ParsedTemplateInfo &TemplateInfo, ForRangeInit *FRI) {
|
|
Declarator &D, const ParsedTemplateInfo &TemplateInfo, ForRangeInit *FRI) {
|
|
|
|
+ // RAII type used to track whether we're inside an initializer.
|
|
|
|
+ struct InitializerScopeRAII {
|
|
|
|
+ Parser &P;
|
|
|
|
+ Declarator &D;
|
|
|
|
+ Decl *ThisDecl;
|
|
|
|
+
|
|
|
|
+ InitializerScopeRAII(Parser &P, Declarator &D, Decl *ThisDecl)
|
|
|
|
+ : P(P), D(D), ThisDecl(ThisDecl) {
|
|
|
|
+ if (ThisDecl && P.getLangOpts().CPlusPlus) {
|
|
|
|
+ Scope *S = nullptr;
|
|
|
|
+ if (D.getCXXScopeSpec().isSet()) {
|
|
|
|
+ P.EnterScope(0);
|
|
|
|
+ S = P.getCurScope();
|
|
|
|
+ }
|
|
|
|
+ P.Actions.ActOnCXXEnterDeclInitializer(S, ThisDecl);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ~InitializerScopeRAII() { pop(); }
|
|
|
|
+ void pop() {
|
|
|
|
+ if (ThisDecl && P.getLangOpts().CPlusPlus) {
|
|
|
|
+ Scope *S = nullptr;
|
|
|
|
+ if (D.getCXXScopeSpec().isSet())
|
|
|
|
+ S = P.getCurScope();
|
|
|
|
+ P.Actions.ActOnCXXExitDeclInitializer(S, ThisDecl);
|
|
|
|
+ if (S)
|
|
|
|
+ P.ExitScope();
|
|
|
|
+ }
|
|
|
|
+ ThisDecl = nullptr;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
// Inform the current actions module that we just parsed this declarator.
|
|
// Inform the current actions module that we just parsed this declarator.
|
|
Decl *ThisDecl = nullptr;
|
|
Decl *ThisDecl = nullptr;
|
|
switch (TemplateInfo.Kind) {
|
|
switch (TemplateInfo.Kind) {
|
|
@@ -2208,10 +2239,7 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
|
|
else
|
|
else
|
|
Diag(ConsumeToken(), diag::err_default_special_members);
|
|
Diag(ConsumeToken(), diag::err_default_special_members);
|
|
} else {
|
|
} else {
|
|
- if (getLangOpts().CPlusPlus && D.getCXXScopeSpec().isSet()) {
|
|
|
|
- EnterScope(0);
|
|
|
|
- Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl);
|
|
|
|
- }
|
|
|
|
|
|
+ InitializerScopeRAII InitScope(*this, D, ThisDecl);
|
|
|
|
|
|
if (Tok.is(tok::code_completion)) {
|
|
if (Tok.is(tok::code_completion)) {
|
|
Actions.CodeCompleteInitializer(getCurScope(), ThisDecl);
|
|
Actions.CodeCompleteInitializer(getCurScope(), ThisDecl);
|
|
@@ -2234,10 +2262,7 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
|
|
FRI->RangeExpr = Init;
|
|
FRI->RangeExpr = Init;
|
|
}
|
|
}
|
|
|
|
|
|
- if (getLangOpts().CPlusPlus && D.getCXXScopeSpec().isSet()) {
|
|
|
|
- Actions.ActOnCXXExitDeclInitializer(getCurScope(), ThisDecl);
|
|
|
|
- ExitScope();
|
|
|
|
- }
|
|
|
|
|
|
+ InitScope.pop();
|
|
|
|
|
|
if (Init.isInvalid()) {
|
|
if (Init.isInvalid()) {
|
|
SmallVector<tok::TokenKind, 2> StopTokens;
|
|
SmallVector<tok::TokenKind, 2> StopTokens;
|
|
@@ -2259,10 +2284,7 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
|
|
ExprVector Exprs;
|
|
ExprVector Exprs;
|
|
CommaLocsTy CommaLocs;
|
|
CommaLocsTy CommaLocs;
|
|
|
|
|
|
- if (getLangOpts().CPlusPlus && D.getCXXScopeSpec().isSet()) {
|
|
|
|
- EnterScope(0);
|
|
|
|
- Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl);
|
|
|
|
- }
|
|
|
|
|
|
+ InitializerScopeRAII InitScope(*this, D, ThisDecl);
|
|
|
|
|
|
llvm::function_ref<void()> ExprListCompleter;
|
|
llvm::function_ref<void()> ExprListCompleter;
|
|
auto ThisVarDecl = dyn_cast_or_null<VarDecl>(ThisDecl);
|
|
auto ThisVarDecl = dyn_cast_or_null<VarDecl>(ThisDecl);
|
|
@@ -2283,11 +2305,6 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
|
|
if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) {
|
|
if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) {
|
|
Actions.ActOnInitializerError(ThisDecl);
|
|
Actions.ActOnInitializerError(ThisDecl);
|
|
SkipUntil(tok::r_paren, StopAtSemi);
|
|
SkipUntil(tok::r_paren, StopAtSemi);
|
|
-
|
|
|
|
- if (getLangOpts().CPlusPlus && D.getCXXScopeSpec().isSet()) {
|
|
|
|
- Actions.ActOnCXXExitDeclInitializer(getCurScope(), ThisDecl);
|
|
|
|
- ExitScope();
|
|
|
|
- }
|
|
|
|
} else {
|
|
} else {
|
|
// Match the ')'.
|
|
// Match the ')'.
|
|
T.consumeClose();
|
|
T.consumeClose();
|
|
@@ -2295,10 +2312,7 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
|
|
assert(!Exprs.empty() && Exprs.size()-1 == CommaLocs.size() &&
|
|
assert(!Exprs.empty() && Exprs.size()-1 == CommaLocs.size() &&
|
|
"Unexpected number of commas!");
|
|
"Unexpected number of commas!");
|
|
|
|
|
|
- if (getLangOpts().CPlusPlus && D.getCXXScopeSpec().isSet()) {
|
|
|
|
- Actions.ActOnCXXExitDeclInitializer(getCurScope(), ThisDecl);
|
|
|
|
- ExitScope();
|
|
|
|
- }
|
|
|
|
|
|
+ InitScope.pop();
|
|
|
|
|
|
ExprResult Initializer = Actions.ActOnParenListExpr(T.getOpenLocation(),
|
|
ExprResult Initializer = Actions.ActOnParenListExpr(T.getOpenLocation(),
|
|
T.getCloseLocation(),
|
|
T.getCloseLocation(),
|
|
@@ -2311,17 +2325,11 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
|
|
// Parse C++0x braced-init-list.
|
|
// Parse C++0x braced-init-list.
|
|
Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
|
|
Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
|
|
|
|
|
|
- if (D.getCXXScopeSpec().isSet()) {
|
|
|
|
- EnterScope(0);
|
|
|
|
- Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl);
|
|
|
|
- }
|
|
|
|
|
|
+ InitializerScopeRAII InitScope(*this, D, ThisDecl);
|
|
|
|
|
|
ExprResult Init(ParseBraceInitializer());
|
|
ExprResult Init(ParseBraceInitializer());
|
|
|
|
|
|
- if (D.getCXXScopeSpec().isSet()) {
|
|
|
|
- Actions.ActOnCXXExitDeclInitializer(getCurScope(), ThisDecl);
|
|
|
|
- ExitScope();
|
|
|
|
- }
|
|
|
|
|
|
+ InitScope.pop();
|
|
|
|
|
|
if (Init.isInvalid()) {
|
|
if (Init.isInvalid()) {
|
|
Actions.ActOnInitializerError(ThisDecl);
|
|
Actions.ActOnInitializerError(ThisDecl);
|