Index: clang/include/clang/Sema/Sema.h =================================================================== --- clang/include/clang/Sema/Sema.h +++ clang/include/clang/Sema/Sema.h @@ -3503,13 +3503,18 @@ void ActOnExitFunctionContext(); /// If \p AllowLambda is true, treat lambda as function. - DeclContext *getFunctionLevelDeclContext(bool AllowLambda = false); + DeclContext *getFunctionLevelDeclContext(bool AllowLambda = false) const; /// Returns a pointer to the innermost enclosing function, or nullptr if the /// current context is not inside a function. If \p AllowLambda is true, /// this can return the call operator of an enclosing lambda, otherwise /// lambdas are skipped when looking for an enclosing function. - FunctionDecl *getCurFunctionDecl(bool AllowLambda = false); + FunctionDecl *getCurFunctionDecl(bool AllowLambda = false) const; + + bool curFunctionDeclIsConstexpr() const { + const FunctionDecl *FD = getCurFunctionDecl(); + return FD ? FD->isConstexpr() : false; + } /// getCurMethodDecl - If inside of a method body, this returns a pointer to /// the method decl for the method being parsed. If we're currently Index: clang/lib/Sema/Sema.cpp =================================================================== --- clang/lib/Sema/Sema.cpp +++ clang/lib/Sema/Sema.cpp @@ -1438,7 +1438,7 @@ // Helper functions. //===----------------------------------------------------------------------===// -DeclContext *Sema::getFunctionLevelDeclContext(bool AllowLambda) { +DeclContext *Sema::getFunctionLevelDeclContext(bool AllowLambda) const { DeclContext *DC = CurContext; while (true) { @@ -1458,7 +1458,7 @@ /// getCurFunctionDecl - If inside of a function body, this returns a pointer /// to the function decl for the function being parsed. If we're currently /// in a 'block', this returns the containing context. -FunctionDecl *Sema::getCurFunctionDecl(bool AllowLambda) { +FunctionDecl *Sema::getCurFunctionDecl(bool AllowLambda) const { DeclContext *DC = getFunctionLevelDeclContext(AllowLambda); return dyn_cast(DC); } Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -15542,11 +15542,14 @@ bool IsConstexpr) { llvm::SaveAndRestore ConstantContext( isConstantEvaluatedOverride, IsConstexpr || isa(E)); + CheckImplicitConversions(E, CheckLoc); if (!E->isInstantiationDependent()) CheckUnsequencedOperations(E); - if (!IsConstexpr && !E->isValueDependent()) + + if (!IsConstexpr && !E->isValueDependent() && !curFunctionDeclIsConstexpr()) CheckForIntOverflow(E); + DiagnoseMisalignedMembers(); } Index: clang/unittests/Support/TimeProfilerTest.cpp =================================================================== --- clang/unittests/Support/TimeProfilerTest.cpp +++ clang/unittests/Support/TimeProfilerTest.cpp @@ -178,9 +178,7 @@ ASSERT_TRUE(TraceGraph == R"( Frontend | EvaluateAsRValue () -| EvaluateForOverflow () | EvaluateAsRValue () -| EvaluateForOverflow () | isPotentialConstantExpr (slow_namespace::slow_func) | EvaluateAsBooleanCondition () | | EvaluateAsRValue ()