diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 1b2d7c86a9625..c89488e54ef49 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -610,7 +610,8 @@ Bug Fixes in This Version of template classes. Fixes (`#68543 `_, `#42496 `_, - `#77071 `_) + `#77071 `_, + `#77411 `_) - Fixed an issue when a shift count larger than ``__INT64_MAX__``, in a right shift operation, could result in missing warnings about ``shift count >= width of type`` or internal compiler error. diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index c8c5a51bf9f94..e7a6550b1c993 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -6192,6 +6192,13 @@ bool TreeTransform::TransformExceptionSpec( // Instantiate a dynamic noexcept expression, if any. if (isComputedNoexcept(ESI.Type)) { + // Update this scrope because ContextDecl in Sema will be used in + // TransformExpr. + auto *Method = dyn_cast_if_present(ESI.SourceTemplate); + Sema::CXXThisScopeRAII ThisScope( + SemaRef, Method ? Method->getParent() : nullptr, + Method ? Method->getMethodQualifiers() : Qualifiers{}, + Method != nullptr); EnterExpressionEvaluationContext Unevaluated( getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated); ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr); diff --git a/clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp b/clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp index 11b1093f9064f..5e56f19477d6c 100644 --- a/clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp +++ b/clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp @@ -64,6 +64,21 @@ namespace DependentDefaultCtorExceptionSpec { struct A { multimap Map; } a; static_assert(noexcept(A())); + + template struct NoexceptWithThis { + int ca; + template auto foo(T) noexcept(ca) { return true; } + // expected-error@-1 {{noexcept specifier argument is not a constant expression}} + // expected-note@-2 {{in instantiation of exception specification}} + // expected-note@-3 {{implicit use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function}} + }; + struct InstantiateFromAnotherClass { + template (&B::foo))> // expected-note {{in instantiation of function template specialization}} + InstantiateFromAnotherClass(B *) {} // expected-note {{in instantiation of default argument}} + }; + NoexceptWithThis f{}; + // Don't crash here. + InstantiateFromAnotherClass b{&f}; // expected-note {{while substituting deduced template arguments into function template}} } #endif