Skip to content

Commit df2513c

Browse files
committed
[clang][Interp] Fix three-way comparison detection
Instead of using !T && CPlusPlus, just check the BinaryOperator's opcode. Turns out we also hit this code path for some assignments of structs in C++.
1 parent d72e8c2 commit df2513c

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ bool ByteCodeExprGen<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
464464
// Special case for C++'s three-way/spaceship operator <=>, which
465465
// returns a std::{strong,weak,partial}_ordering (which is a class, so doesn't
466466
// have a PrimType).
467-
if (!T && Ctx.getLangOpts().CPlusPlus) {
467+
if (!T && BO->getOpcode() == BO_Cmp) {
468468
if (DiscardResult)
469469
return true;
470470
const ComparisonCategoryInfo *CmpInfo =

clang/test/SemaCXX/conditional-expr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify=expected,expected-cxx11 -std=c++11 -Wsign-conversion %s
2+
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify=expected,expected-cxx11 -std=c++11 -Wsign-conversion %s -fexperimental-new-constant-interpreter
23
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify=expected,expected-cxx17 -std=c++17 -Wsign-conversion %s
4+
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify=expected,expected-cxx17 -std=c++17 -Wsign-conversion %s -fexperimental-new-constant-interpreter
35

46
// C++ rules for ?: are a lot stricter than C rules, and have to take into
57
// account more conversion options.

0 commit comments

Comments
 (0)