Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:37:00

0001 //===--- EnterExpressionEvaluationContext.h ---------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_SEMA_ENTEREXPRESSIONEVALUATIONCONTEXT_H
0010 #define LLVM_CLANG_SEMA_ENTEREXPRESSIONEVALUATIONCONTEXT_H
0011 
0012 #include "clang/Sema/Sema.h"
0013 
0014 namespace clang {
0015 
0016 class Decl;
0017 
0018 /// RAII object that enters a new expression evaluation context.
0019 class EnterExpressionEvaluationContext {
0020   Sema &Actions;
0021   bool Entered = true;
0022 
0023 public:
0024   EnterExpressionEvaluationContext(
0025       Sema &Actions, Sema::ExpressionEvaluationContext NewContext,
0026       Decl *LambdaContextDecl = nullptr,
0027       Sema::ExpressionEvaluationContextRecord::ExpressionKind ExprContext =
0028           Sema::ExpressionEvaluationContextRecord::EK_Other,
0029       bool ShouldEnter = true)
0030       : Actions(Actions), Entered(ShouldEnter) {
0031     if (Entered)
0032       Actions.PushExpressionEvaluationContext(NewContext, LambdaContextDecl,
0033                                               ExprContext);
0034   }
0035   EnterExpressionEvaluationContext(
0036       Sema &Actions, Sema::ExpressionEvaluationContext NewContext,
0037       Sema::ReuseLambdaContextDecl_t,
0038       Sema::ExpressionEvaluationContextRecord::ExpressionKind ExprContext =
0039           Sema::ExpressionEvaluationContextRecord::EK_Other)
0040       : Actions(Actions) {
0041     Actions.PushExpressionEvaluationContext(
0042         NewContext, Sema::ReuseLambdaContextDecl, ExprContext);
0043   }
0044 
0045   enum InitListTag { InitList };
0046   EnterExpressionEvaluationContext(Sema &Actions, InitListTag,
0047                                    bool ShouldEnter = true)
0048       : Actions(Actions), Entered(false) {
0049     // In C++11 onwards, narrowing checks are performed on the contents of
0050     // braced-init-lists, even when they occur within unevaluated operands.
0051     // Therefore we still need to instantiate constexpr functions used in such
0052     // a context.
0053     if (ShouldEnter && Actions.isUnevaluatedContext() &&
0054         Actions.getLangOpts().CPlusPlus11) {
0055       Actions.PushExpressionEvaluationContext(
0056           Sema::ExpressionEvaluationContext::UnevaluatedList);
0057       Entered = true;
0058     }
0059   }
0060 
0061   ~EnterExpressionEvaluationContext() {
0062     if (Entered)
0063       Actions.PopExpressionEvaluationContext();
0064   }
0065 };
0066 
0067 } // namespace clang
0068 
0069 #endif