This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Reject increment of bool value in unevaluated contexts after C++17
ClosedPublic

Authored by yronglin on Jun 6 2023, 4:44 AM.

Details

Summary

Clang now incorrectly allowed increment of bool in unevaluated contexts, we set diagnostic::ext_increment_bool to be SFINAEFailure to fix this issue.

template<class T> auto f(T t) -> decltype(++t);
auto f(...) -> void;
void g() {
  f(true);  // Clang wrongly makes this a hard error
}
template <class T>
concept can_increment = requires(T t) { ++t; };

template <class T> void f() {
  static_assert(requires(T t) { ++t; }); // Incorrectly allowed
}

int main() {
  f<bool>();

  static_assert(!can_increment<bool>); // Incorrectly fails

  bool b = false;
  ++b; // Correctly rejected
}

Fix issue: https://github.com/llvm/llvm-project/issues/47517

Diff Detail

Event Timeline

yronglin created this revision.Jun 6 2023, 4:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 6 2023, 4:44 AM
yronglin requested review of this revision.Jun 6 2023, 4:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 6 2023, 4:44 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
yronglin edited the summary of this revision. (Show Details)Jun 6 2023, 4:45 AM
yronglin edited reviewers, added: CaseyCarter; removed: Quuxplusone.

This should have a release note.

I think the bug is asking to make this a SFINAE failure (it isn't clear what you mean by "SFINAE Friendly"). Our mechanism for that is to mark the diagnostic SFINAEError.

clang/lib/Sema/SemaExpr.cpp
14603 ↗(On Diff #528795)

I think what you really need to do is just set ext_increment_bool to be SFINAEError in DiagnosticSemaKinds.td, right? Not all of this?

yronglin updated this revision to Diff 528847.Jun 6 2023, 7:08 AM

Address comments

yronglin marked an inline comment as done.EditedJun 6 2023, 7:11 AM

This should have a release note.

I think the bug is asking to make this a SFINAE failure (it isn't clear what you mean by "SFINAE Friendly"). Our mechanism for that is to mark the diagnostic SFINAEError.

Thanks for your review and advice @erichkeane ! I think the title need update.

clang/lib/Sema/SemaExpr.cpp
14603 ↗(On Diff #528795)

Thanks for your advice, your are right.

yronglin retitled this revision from [Clang] Make increment bool SFINAE-friendly to [Clang] Make increment bool SFINAE failure.Jun 6 2023, 7:20 AM
yronglin updated this revision to Diff 528856.Jun 6 2023, 7:28 AM
yronglin marked an inline comment as done.

Add release notes.

yronglin retitled this revision from [Clang] Make increment bool SFINAE failure to [Clang] Reject increment of bool value in unevaluated contexts after C++17..Jun 6 2023, 7:32 AM
yronglin edited the summary of this revision. (Show Details)
yronglin edited the summary of this revision. (Show Details)
yronglin retitled this revision from [Clang] Reject increment of bool value in unevaluated contexts after C++17. to [Clang] Reject increment of bool value in unevaluated contexts after C++17.
erichkeane accepted this revision.Jun 6 2023, 7:36 AM
This revision is now accepted and ready to land.Jun 6 2023, 7:36 AM

Thanks for your review @erichkeane ! Seems the CI failure not caused by this patch.

Thanks for your review @erichkeane ! Seems the CI failure not caused by this patch.

I agree, I don't think it is related.

This revision was landed with ongoing or failed builds.Jun 6 2023, 8:58 AM
This revision was automatically updated to reflect the committed changes.

Thanks for your review @erichkeane ! Seems the CI failure not caused by this patch.

I agree, I don't think it is related.

Thanks, landed in 540294845babbb2be909ea456323d7bc8a1763df