diff options
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 26 | ||||
-rw-r--r-- | clang/lib/Sema/SemaLambda.cpp | 16 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 10 |
3 files changed, 22 insertions, 30 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 4511d2da03b..e68b8b8a348 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -14243,22 +14243,21 @@ void Sema::ActOnPureSpecifier(Decl *D, SourceLocation ZeroLoc) { Diag(D->getLocation(), diag::err_illegal_initializer); } -/// \brief Determine whether the given declaration is a global variable or -/// static data member. -static bool isNonlocalVariable(const Decl *D) { +/// \brief Determine whether the given declaration is a static data member. +static bool isStaticDataMember(const Decl *D) { if (const VarDecl *Var = dyn_cast_or_null<VarDecl>(D)) - return Var->hasGlobalStorage(); + return Var->isStaticDataMember(); return false; } -/// Invoked when we are about to parse an initializer for the declaration -/// 'Dcl'. +/// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse +/// an initializer for the out-of-line declaration 'Dcl'. The scope +/// is a fresh scope pushed for just this purpose. /// /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a /// static data member of class X, names should be looked up in the scope of -/// class X. If the declaration had a scope specifier, a scope will have -/// been created and passed in for this purpose. Otherwise, S will be null. +/// class X. void Sema::ActOnCXXEnterDeclInitializer(Scope *S, Decl *D) { // If there is no declaration, there was an error parsing it. if (!D || D->isInvalidDecl()) @@ -14268,27 +14267,28 @@ void Sema::ActOnCXXEnterDeclInitializer(Scope *S, Decl *D) { // might not be out of line if the specifier names the current namespace: // extern int n; // int ::n = 0; - if (S && D->isOutOfLine()) + if (D->isOutOfLine()) EnterDeclaratorContext(S, D->getDeclContext()); // If we are parsing the initializer for a static data member, push a // new expression evaluation context that is associated with this static // data member. - if (isNonlocalVariable(D)) + if (isStaticDataMember(D)) PushExpressionEvaluationContext( ExpressionEvaluationContext::PotentiallyEvaluated, D); } -/// Invoked after we are finished parsing an initializer for the declaration D. +/// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an +/// initializer for the out-of-line declaration 'D'. void Sema::ActOnCXXExitDeclInitializer(Scope *S, Decl *D) { // If there is no declaration, there was an error parsing it. if (!D || D->isInvalidDecl()) return; - if (isNonlocalVariable(D)) + if (isStaticDataMember(D)) PopExpressionEvaluationContext(); - if (S && D->isOutOfLine()) + if (D->isOutOfLine()) ExitDeclaratorContext(S); } diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp index 996ed3ea7e4..bbd7c4a0937 100644 --- a/clang/lib/Sema/SemaLambda.cpp +++ b/clang/lib/Sema/SemaLambda.cpp @@ -288,9 +288,7 @@ Sema::getCurrentMangleNumberContext(const DeclContext *DC, Normal, DefaultArgument, DataMember, - StaticDataMember, - InlineVariable, - VariableTemplate + StaticDataMember } Kind = Normal; // Default arguments of member function parameters that appear in a class @@ -305,14 +303,6 @@ Sema::getCurrentMangleNumberContext(const DeclContext *DC, } else if (VarDecl *Var = dyn_cast<VarDecl>(ManglingContextDecl)) { if (Var->getDeclContext()->isRecord()) Kind = StaticDataMember; - else if (Var->getMostRecentDecl()->isInline()) - Kind = InlineVariable; - else if (Var->getDescribedVarTemplate()) - Kind = VariableTemplate; - else if (auto *VTS = dyn_cast<VarTemplateSpecializationDecl>(Var)) { - if (!VTS->isExplicitSpecialization()) - Kind = VariableTemplate; - } } else if (isa<FieldDecl>(ManglingContextDecl)) { Kind = DataMember; } @@ -353,10 +343,6 @@ Sema::getCurrentMangleNumberContext(const DeclContext *DC, // -- the in-class initializers of class members case DefaultArgument: // -- default arguments appearing in class definitions - case InlineVariable: - // -- the initializers of inline variables - case VariableTemplate: - // -- the initializers of templated variables return &ExprEvalContexts.back().getMangleNumberingContext(Context); } diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 2c51c57bf39..e702d3c7238 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -4140,8 +4140,12 @@ void Sema::InstantiateVariableInitializer( Var->setImplicitlyInline(); if (OldVar->getInit()) { - EnterExpressionEvaluationContext Evaluated( - *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated, Var); + if (Var->isStaticDataMember() && !OldVar->isOutOfLine()) + PushExpressionEvaluationContext( + Sema::ExpressionEvaluationContext::ConstantEvaluated, OldVar); + else + PushExpressionEvaluationContext( + Sema::ExpressionEvaluationContext::PotentiallyEvaluated, OldVar); // Instantiate the initializer. ExprResult Init; @@ -4169,6 +4173,8 @@ void Sema::InstantiateVariableInitializer( // because of a bogus initializer. Var->setInvalidDecl(); } + + PopExpressionEvaluationContext(); } else { if (Var->isStaticDataMember()) { if (!Var->isOutOfLine()) |