@@ -3098,6 +3098,58 @@ TEST(TransferTest, ResultObjectLocationForCXXOperatorCallExpr) {
3098
3098
});
3099
3099
}
3100
3100
3101
+ // Check that the `std::strong_ordering` object returned by builtin `<=>` has a
3102
+ // correctly modeled result object location.
3103
+ TEST (TransferTest, ResultObjectLocationForBuiltinSpaceshipOperator) {
3104
+ std::string Code = R"(
3105
+ namespace std {
3106
+ // This is the minimal definition required to get
3107
+ // `Sema::CheckComparisonCategoryType()` to accept this fake.
3108
+ struct strong_ordering {
3109
+ enum class ordering { less, equal, greater };
3110
+ ordering o;
3111
+ static const strong_ordering less;
3112
+ static const strong_ordering equivalent;
3113
+ static const strong_ordering equal;
3114
+ static const strong_ordering greater;
3115
+ };
3116
+
3117
+ inline constexpr strong_ordering strong_ordering::less =
3118
+ { strong_ordering::ordering::less };
3119
+ inline constexpr strong_ordering strong_ordering::equal =
3120
+ { strong_ordering::ordering::equal };
3121
+ inline constexpr strong_ordering strong_ordering::equivalent =
3122
+ { strong_ordering::ordering::equal };
3123
+ inline constexpr strong_ordering strong_ordering::greater =
3124
+ { strong_ordering::ordering::greater };
3125
+ }
3126
+ void target(int i, int j) {
3127
+ auto ordering = i <=> j;
3128
+ // [[p]]
3129
+ }
3130
+ )" ;
3131
+ using ast_matchers::binaryOperator;
3132
+ using ast_matchers::hasOperatorName;
3133
+ using ast_matchers::match;
3134
+ using ast_matchers::selectFirst;
3135
+ using ast_matchers::traverse;
3136
+ runDataflow (
3137
+ Code,
3138
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
3139
+ ASTContext &ASTCtx) {
3140
+ const Environment &Env = getEnvironmentAtAnnotation (Results, " p" );
3141
+
3142
+ auto *Spaceship = selectFirst<BinaryOperator>(
3143
+ " op" ,
3144
+ match (binaryOperator (hasOperatorName (" <=>" )).bind (" op" ), ASTCtx));
3145
+
3146
+ EXPECT_EQ (
3147
+ &Env.getResultObjectLocation (*Spaceship),
3148
+ &getLocForDecl<RecordStorageLocation>(ASTCtx, Env, " ordering" ));
3149
+ },
3150
+ LangStandard::lang_cxx20);
3151
+ }
3152
+
3101
3153
TEST (TransferTest, ResultObjectLocationForStdInitializerListExpr) {
3102
3154
std::string Code = R"(
3103
3155
namespace std {
0 commit comments