This patch fixes the wrong signal from the constexpr evaluator that
[[gnu::weak]] member pointer comparison is valid, while it is emitting
notes on them.
I found a crashing case fixed by this change and added it as a test
case: https://godbolt.org/z/8391fGjGn
I noticed this while I was working on D146358.
Differential Revision: https://reviews.llvm.org/D148419
(`#61417 <https://github.com/llvm/llvm-project/issues/61417>`_)
- Fix crash after suggesting typo correction to constexpr if condition.
(`#61885 <https://github.com/llvm/llvm-project/issues/61885>`_)
+- Clang constexpr evaluator now treats comparison of [[gnu::weak]]-attributed
+ member pointer as an invalid expression.
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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:
--- /dev/null
+// 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}}
+