Fixes PR39858

# Details

- Reviewers
rsmith rjmccall efriedma - Commits
- rG9f935e874979: [ExprConstant] Handle compound assignment when LHS has integral type and RHS…

rL349444: [ExprConstant] Handle compound assignment when LHS has integral type and RHS…

rC349444: [ExprConstant] Handle compound assignment when LHS has integral type and RHS…

# Diff Detail

- Repository
- rC Clang

### Event Timeline

clang/test/SemaCXX/constant-expression-cxx1y.cpp | ||
---|---|---|

343 | Because adding |

Added parentheses. Restored the original tests and added more tests to the end of this function.

clang/lib/AST/ExprConstant.cpp | ||
---|---|---|

3441 | Can we more fundamentally restructure this entire handler so that, if the compound assignment's computation result type is an arithmetic type, we just promote both operands to that type, do the arithmetic there, and then coerce back down? This is C++, so the LHS type imposes almost no restrictions on the RHS type; also, this is Clang, where we support way too many arithmetic types for our own good. |

clang/lib/AST/ExprConstant.cpp | ||
---|---|---|

3441 | It seems the conditional statement is unavoidable, because |

clang/lib/AST/ExprConstant.cpp | ||
---|---|---|

3453 | Does this work for the float += int case? |

clang/lib/AST/ExprConstant.cpp | ||
---|---|---|

3441 | But we can have | |

3453 | IIRC, the RHS gets promoted to the computation type in Sema. |

clang/lib/AST/ExprConstant.cpp | ||
---|---|---|

3441 | That's what I mean by "add a layer", and I think it's unworthy. Maybe it makes more sense as part of a larger scale rewrite, but that's more than I can deal with. |

clang/lib/AST/ExprConstant.cpp | ||
---|---|---|

3441 | Ah, I see that all three Please at least adjust the code to make the |

clang/lib/AST/ExprConstant.cpp | ||
---|---|---|

3453 | Yes, in the float += int case, the RHS is the result of ImplicitCastExpr of kind IntegralToFloating. And |