Author: Timm Bäder Date: 2024-05-21T13:20:42+02:00 New Revision: 18e7bcbae12bc2e2cf9888844a0b3f12075f508c
URL: https://github.com/llvm/llvm-project/commit/18e7bcbae12bc2e2cf9888844a0b3f12075f508c DIFF: https://github.com/llvm/llvm-project/commit/18e7bcbae12bc2e2cf9888844a0b3f12075f508c.diff LOG: [clang][Interp] Reject inc/dec ops before C++ 14 Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/cxx11.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 33d69d04487de..859a3fabea32b 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -3395,6 +3395,9 @@ bool ByteCodeExprGen<Emitter>::VisitUnaryOperator(const UnaryOperator *E) { switch (E->getOpcode()) { case UO_PostInc: { // x++ + if (!Ctx.getLangOpts().CPlusPlus14) + return this->emitInvalid(E); + if (!this->visit(SubExpr)) return false; @@ -3413,6 +3416,9 @@ bool ByteCodeExprGen<Emitter>::VisitUnaryOperator(const UnaryOperator *E) { return DiscardResult ? this->emitIncPop(*T, E) : this->emitInc(*T, E); } case UO_PostDec: { // x-- + if (!Ctx.getLangOpts().CPlusPlus14) + return this->emitInvalid(E); + if (!this->visit(SubExpr)) return false; @@ -3431,6 +3437,9 @@ bool ByteCodeExprGen<Emitter>::VisitUnaryOperator(const UnaryOperator *E) { return DiscardResult ? this->emitDecPop(*T, E) : this->emitDec(*T, E); } case UO_PreInc: { // ++x + if (!Ctx.getLangOpts().CPlusPlus14) + return this->emitInvalid(E); + if (!this->visit(SubExpr)) return false; @@ -3475,6 +3484,9 @@ bool ByteCodeExprGen<Emitter>::VisitUnaryOperator(const UnaryOperator *E) { return E->isGLValue() || this->emitLoadPop(*T, E); } case UO_PreDec: { // --x + if (!Ctx.getLangOpts().CPlusPlus14) + return this->emitInvalid(E); + if (!this->visit(SubExpr)) return false; diff --git a/clang/test/AST/Interp/cxx11.cpp b/clang/test/AST/Interp/cxx11.cpp index 993e3618a3784..f06a5dd173cba 100644 --- a/clang/test/AST/Interp/cxx11.cpp +++ b/clang/test/AST/Interp/cxx11.cpp @@ -30,3 +30,19 @@ constexpr S s = { 5 }; constexpr const int *p = &s.m + 1; constexpr const int *np2 = &(*(int(*)[4])nullptr)[0]; // ok + +constexpr int preDec(int x) { // both-error {{never produces a constant expression}} + return --x; // both-note {{subexpression}} +} + +constexpr int postDec(int x) { // both-error {{never produces a constant expression}} + return x--; // both-note {{subexpression}} +} + +constexpr int preInc(int x) { // both-error {{never produces a constant expression}} + return ++x; // both-note {{subexpression}} +} + +constexpr int postInc(int x) { // both-error {{never produces a constant expression}} + return x++; // both-note {{subexpression}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits