Skip to content

Latest commit

 

History

History
35 lines (27 loc) · 1.15 KB

c6395.md

File metadata and controls

35 lines (27 loc) · 1.15 KB
title description ms.date f1_keywords helpviewer_keywords
Warning C6395
Describes the Microsoft C/C++ code analysis warning C6395, its causes, and how to address it.
10/12/2023
C6395
EVAL_ORDER_CHANGE
C6395

Warning C6395

%variable% has unsequenced reads and/or writes before C++17; changing the language standard might change the behavior of the code.

Remarks

C++17 made the evaluation order of certain expressions stricter. MSVC complied, which changed the evaluation order for some expressions. Thus, changing the language version might change the observable behavior of the program. This check diagnoses some of the cases where the meaning of the code changes due to switching language versions.

Code analysis name: EVAL_ORDER_CHANGE

Example

void foo(int* a, int i)
{
    a[++i] = i; // Warning: 'i' has unsequenced reads and/or writes before C++17; changing the language standard might change the behavior of the code
}

To solve this problem, separate the side effects from the rest of the expression to make the evaluation order well defined:

void foo(int* a, int i)
{
    ++i;
    a[i] = i; // No warning.
}