Skip to content

[clang]use correct this scope to evaluate noexcept expr #77416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,8 @@ Bug Fixes in This Version
of template classes. Fixes
(`#68543 <https://github.com/llvm/llvm-project/issues/68543>`_,
`#42496 <https://github.com/llvm/llvm-project/issues/42496>`_,
`#77071 <https://github.com/llvm/llvm-project/issues/77071>`_)
`#77071 <https://github.com/llvm/llvm-project/issues/77071>`_,
`#77411 <https://github.com/llvm/llvm-project/issues/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.
Expand Down
7 changes: 7 additions & 0 deletions clang/lib/Sema/TreeTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -6192,6 +6192,13 @@ bool TreeTransform<Derived>::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<CXXMethodDecl>(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);
Expand Down
15 changes: 15 additions & 0 deletions clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ namespace DependentDefaultCtorExceptionSpec {
struct A { multimap<int> Map; } a;

static_assert(noexcept(A()));

template <class> struct NoexceptWithThis {
int ca;
template <class T> 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 <class B, class T = decltype(static_cast<bool (B::*)(int)>(&B::foo))> // expected-note {{in instantiation of function template specialization}}
InstantiateFromAnotherClass(B *) {} // expected-note {{in instantiation of default argument}}
};
NoexceptWithThis<int> f{};
// Don't crash here.
InstantiateFromAnotherClass b{&f}; // expected-note {{while substituting deduced template arguments into function template}}
}

#endif
Expand Down