diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -312,6 +312,8 @@ (`#61417 `_) - Fix crash after suggesting typo correction to constexpr if condition. (`#61885 `_) +- Clang constexpr evaluator now treats comparison of [[gnu::weak]]-attributed + member pointer as an invalid expression. Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -13142,12 +13142,12 @@ if (LHSValue.getDecl() && LHSValue.getDecl()->isWeak()) { Info.FFDiag(E, diag::note_constexpr_mem_pointer_weak_comparison) << LHSValue.getDecl(); - return true; + return false; } if (RHSValue.getDecl() && RHSValue.getDecl()->isWeak()) { Info.FFDiag(E, diag::note_constexpr_mem_pointer_weak_comparison) << RHSValue.getDecl(); - return true; + return false; } // C++11 [expr.eq]p2: diff --git a/clang/test/SemaCXX/crash-lambda-weak-attr.cpp b/clang/test/SemaCXX/crash-lambda-weak-attr.cpp new file mode 100644 --- /dev/null +++ b/clang/test/SemaCXX/crash-lambda-weak-attr.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct Weak { + [[gnu::weak]]void weak_method(); +}; +static_assert([](){ return &Weak::weak_method != nullptr; }()); // expected-error {{static assertion expression is not an integral constant expression}} \ + // expected-note {{comparison against pointer to weak member 'Weak::weak_method' can only be performed at runtime}} \ + // expected-note {{in call to}} +