diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index 9c3d58d5619c4..43cbc2ff292c0 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -525,8 +525,7 @@ enum class IncDecOp { template bool IncDecHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { - if (Ptr.isDummy()) - return false; + assert(!Ptr.isDummy()); if constexpr (std::is_same_v) { if (!S.getLangOpts().CPlusPlus14) @@ -585,7 +584,7 @@ bool IncDecHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { template ::T> bool Inc(InterpState &S, CodePtr OpPC) { const Pointer &Ptr = S.Stk.pop(); - if (Ptr.isDummy()) + if (!CheckDummy(S, OpPC, Ptr)) return false; if (!CheckInitialized(S, OpPC, Ptr, AK_Increment)) return false; @@ -599,7 +598,7 @@ bool Inc(InterpState &S, CodePtr OpPC) { template ::T> bool IncPop(InterpState &S, CodePtr OpPC) { const Pointer &Ptr = S.Stk.pop(); - if (Ptr.isDummy()) + if (!CheckDummy(S, OpPC, Ptr)) return false; if (!CheckInitialized(S, OpPC, Ptr, AK_Increment)) return false; @@ -614,7 +613,7 @@ bool IncPop(InterpState &S, CodePtr OpPC) { template ::T> bool Dec(InterpState &S, CodePtr OpPC) { const Pointer &Ptr = S.Stk.pop(); - if (Ptr.isDummy()) + if (!CheckDummy(S, OpPC, Ptr)) return false; if (!CheckInitialized(S, OpPC, Ptr, AK_Decrement)) return false; @@ -628,7 +627,7 @@ bool Dec(InterpState &S, CodePtr OpPC) { template ::T> bool DecPop(InterpState &S, CodePtr OpPC) { const Pointer &Ptr = S.Stk.pop(); - if (Ptr.isDummy()) + if (!CheckDummy(S, OpPC, Ptr)) return false; if (!CheckInitialized(S, OpPC, Ptr, AK_Decrement)) return false; diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp index d86609108ca44..7ae8499b1156d 100644 --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -839,6 +839,18 @@ namespace IncDec { return a[1]; } static_assert(f() == 3, ""); + + int nonconst(int a) { // both-note 4{{declared here}} + static_assert(a++, ""); // both-error {{not an integral constant expression}} \ + // both-note {{function parameter 'a' with unknown value cannot be used in a constant expression}} + static_assert(a--, ""); // both-error {{not an integral constant expression}} \ + // both-note {{function parameter 'a' with unknown value cannot be used in a constant expression}} + static_assert(++a, ""); // both-error {{not an integral constant expression}} \ + // both-note {{function parameter 'a' with unknown value cannot be used in a constant expression}} + static_assert(--a, ""); // both-error {{not an integral constant expression}} \ + // both-note {{function parameter 'a' with unknown value cannot be used in a constant expression}} + } + }; #endif