You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/porting/visual-cpp-change-history-2003-2015.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -2733,7 +2733,7 @@ When you upgrade to a new version of the Visual C++ compiler, you might encounte
2733
2733
2734
2734
- Support for Windows 95, Windows 98, Windows Millennium Edition, and Windows NT 4.0 has been removed.
2735
2735
2736
-
- When compiling in debug mode with _HAS_ITERATOR_DEBUGGING defined, an application will now assert when an iterator attempts to increment or decrement past the bounds of the underlying container.
2736
+
- When compiling in debug mode with _HAS_ITERATOR_DEBUGGING defined (superseded by [_ITERATOR_DEBUG_LEVEL](../standard-library/iterator-debug-level.md) after Visual Studio 2010), an application will now assert when an iterator attempts to increment or decrement past the bounds of the underlying container.
2737
2737
2738
2738
- The member variable c of the stack Class is now declared protected. Previously, this member variable was declared public.
2739
2739
@@ -2819,7 +2819,7 @@ When you upgrade to a new version of the Visual C++ compiler, you might encounte
2819
2819
2820
2820
- When calling valarray::resize(), the contents of the valarray will be lost and will be replaced by default values. The resize() method is intended to reinitialize the valarray rather than grow it dynamically like a vector.
2821
2821
2822
-
- Debug Iterators: Applications built with a debug version of the C-Runtime Library and which use iterators incorrectly might begin to see asserts at runtime. To disable these asserts, you must define _HAS_ITERATOR_DEBUGGING to 0. For more information, see [Debug Iterator Support](../standard-library/debug-iterator-support.md)
2822
+
- Debug Iterators: Applications built with a debug version of the C-Runtime Library and which use iterators incorrectly might begin to see asserts at runtime. To disable these asserts, you must define _HAS_ITERATOR_DEBUGGING (superseded by [_ITERATOR_DEBUG_LEVEL](../standard-library/iterator-debug-level.md) after Visual Studio 2010) to 0. For more information, see [Debug Iterator Support](../standard-library/debug-iterator-support.md)
Copy file name to clipboardExpand all lines: docs/standard-library/debug-iterator-support.md
+32-32Lines changed: 32 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -8,8 +8,6 @@ ms.technology:
8
8
- "devlang-cpp"
9
9
ms.tgt_pltfrm: ""
10
10
ms.topic: "article"
11
-
f1_keywords:
12
-
- "_HAS_ITERATOR_DEBUGGING symbol"
13
11
dev_langs:
14
12
- "C++"
15
13
helpviewer_keywords:
@@ -42,19 +40,20 @@ translation.priority.ht:
42
40
- "zh-tw"
43
41
---
44
42
# Debug Iterator Support
45
-
The Visual C++ run-time library detects incorrect iterator use, and asserts and displays a dialog box at run time. To enable debug iterator support, you must use a debug version of a C run-time library to compile your program. For more information, see [CRT Library Features](../c-runtime-library/crt-library-features.md). For information about how to use iterators, see [Checked Iterators](../standard-library/checked-iterators.md).
43
+
The Visual C++ run-time library detects incorrect iterator use, and asserts and displays a dialog box at run time. To enable debug iterator support, you must use debug versions of the C++ Standard Library and C Runtime Library to compile your program. For more information, see [CRT Library Features](../c-runtime-library/crt-library-features.md). For information about how to use checked iterators, see [Checked Iterators](../standard-library/checked-iterators.md).
46
44
47
45
The C++ standard describes how member functions might cause iterators to a container to become invalid. Two examples are:
48
46
49
47
- Erasing an element from a container causes iterators to the element to become invalid.
50
48
51
-
- Increasing the size of a [vector](../standard-library/vector.md)(push or insert) causes iterators into the `vector` to become invalid.
49
+
- Increasing the size of a [vector](../standard-library/vector.md)by using push or insert causes iterators into the `vector` to become invalid.
52
50
53
51
## Example
54
-
If you compile the following program in debug mode, at run time it will assert and terminate.
52
+
If you compile this sample program in debug mode, at run time it asserts and terminates.
55
53
56
54
```cpp
57
-
/* compile with /EHsc /MDd */
55
+
// iterator_debugging_0.cpp
56
+
// compile by using /EHsc /MDd
58
57
#include<vector>
59
58
#include<iostream>
60
59
@@ -71,24 +70,21 @@ int main() {
71
70
std::vector<int>::iterator j = v.end();
72
71
--j;
73
72
74
-
std::cout<<*j<<'\n';
73
+
std::cout << *j << '\n';
75
74
76
75
v.insert(i,25);
77
76
78
-
std::cout<<*j<<'\n'; // Using an old iterator after an insert
77
+
std::cout << *j << '\n'; // Using an old iterator after an insert
79
78
}
80
79
```
81
80
82
81
## Example
83
-
You can use the symbol [_HAS_ITERATOR_DEBUGGING](../standard-library/has-iterator-debugging.md) to turn off the iterator debugging feature in a debug build. The following program does not assert, but still triggers undefined behavior.
84
-
85
-
> [!IMPORTANT]
86
-
> Use `_ITERATOR_DEBUG_LEVEL` to control `_HAS_ITERATOR_DEBUGGING`. For more information, see [_ITERATOR_DEBUG_LEVEL](../standard-library/iterator-debug-level.md).
82
+
You can use the preprocessor macro [_ITERATOR_DEBUG_LEVEL](../standard-library/iterator-debug-level.md) to turn off the iterator debugging feature in a debug build. This program does not assert, but still triggers undefined behavior.
87
83
88
84
```cpp
89
-
//iterator_debugging.cpp
90
-
// compile with: /EHsc /MDd
91
-
#define_HAS_ITERATOR_DEBUGGING 0
85
+
//iterator_debugging_1.cpp
86
+
// compile by using: /EHsc /MDd
87
+
#define_ITERATOR_DEBUG_LEVEL 0
92
88
#include <vector>
93
89
#include <iostream>
94
90
@@ -105,11 +101,11 @@ int main() {
105
101
std::vector<int>::iterator j = v.end();
106
102
--j;
107
103
108
-
std::cout<<*j<<'\n';
104
+
std::cout << *j << '\n';
109
105
110
106
v.insert(i,25);
111
107
112
-
std::cout<<*j<<'\n'; // Using an old iterator after an insert
108
+
std::cout << *j << '\n'; // Using an old iterator after an insert
113
109
}
114
110
```
115
111
@@ -119,12 +115,14 @@ int main() {
119
115
```
120
116
121
117
## Example
122
-
An assert also occurs if you attempt to use an iterator before it is initialized, as shown here:
118
+
An assert also occurs if you attempt to use an iterator before it is initialized, as shown here:
123
119
124
120
```cpp
125
-
/* compile with /EHsc /MDd */
121
+
// iterator_debugging_2.cpp
122
+
// compile by using: /EHsc /MDd
126
123
#include<string>
127
124
usingnamespacestd;
125
+
128
126
intmain() {
129
127
string::iterator i1, i2;
130
128
if (i1 == i2)
@@ -133,10 +131,11 @@ int main() {
133
131
```
134
132
135
133
## Example
136
-
The following code example causes an assertion because the two iterators to the [for_each](../standard-library/algorithm-functions.md#for_each) algorithm are incompatible. Algorithms check to determine whether the iterators that are supplied to them are referencing the same container.
134
+
The following code example causes an assertion because the two iterators to the [for_each](../standard-library/algorithm-functions.md#for_each) algorithm are incompatible. Algorithms check to determine whether the iterators that are supplied to them reference the same container.
137
135
138
136
```cpp
139
-
/* compile with /EHsc /MDd */
137
+
// iterator_debugging_3.cpp
138
+
// compile by using /EHsc /MDd
140
139
#include<algorithm>
141
140
#include<vector>
142
141
usingnamespacestd;
@@ -152,20 +151,20 @@ int main()
152
151
v2.push_back(10);
153
152
v2.push_back(20);
154
153
155
-
// The next line will assert because v1 and v2 are
Notice that this example uses the lambda expression `[] (int& elem) { elem *= 2; }` instead of a functor. Although this choice has no bearing on the assert failure—a similar functor would cause the same failure—lambdas are a very useful way to accomplish compact function object tasks. For more information about lambda expressions, see [Lambda Expressions](../cpp/lambda-expressions-in-cpp.md).
160
+
Notice that this example uses the lambda expression `[] (int& elem) { elem *= 2; }` instead of a functor. Although this choice has no bearing on the assert failure—a similar functor would cause the same failure—lambdas are a very useful way to accomplish compact function object tasks. For more information about lambda expressions, see [Lambda Expressions](../cpp/lambda-expressions-in-cpp.md).
162
161
163
162
## Example
164
-
Debug iterator checking also causes an iterator variable that's declared in a `for` loop to be out of scope when the `for` loop scope ends.
163
+
Debug iterator checks also cause an iterator variable that's declared in a `for` loop to be out of scope when the `for` loop scope ends.
165
164
166
165
```cpp
167
-
//debug_iterator.cpp
168
-
// compile with: /EHsc /MDd
166
+
//iterator_debugging_4.cpp
167
+
// compile by using: /EHsc /MDd
169
168
#include<vector>
170
169
#include<iostream>
171
170
intmain() {
@@ -175,20 +174,21 @@ int main() {
175
174
v.push_back(15);
176
175
v.push_back(20);
177
176
178
-
for (std::vector<int>::iterator i = v.begin(); i != v.end(); ++i)
179
-
;
177
+
for (std::vector<int>::iterator i = v.begin(); i != v.end(); ++i)
178
+
; // do nothing
180
179
--i; // C2065
181
180
}
182
181
```
183
182
184
183
## Example
185
-
Debug iterators have non-trivial destructors. If a destructor does not run, for whatever reason, access violations and data corruption might occur. Consider this example:
184
+
Debug iterators have non-trivial destructors. If a destructor does not run, for whatever reason, access violations and data corruption might occur. Consider this example:
186
185
187
186
```cpp
188
-
/* compile with: /EHsc /MDd */
187
+
// iterator_debugging_5.cpp
188
+
// compile by using: /EHsc /MDd
189
189
#include<vector>
190
190
structbase {
191
-
// FIX: uncomment the next line
191
+
// TO FIX: uncomment the next line
192
192
// virtual ~base() {}
193
193
};
194
194
@@ -207,7 +207,7 @@ int main() {
207
207
```
208
208
209
209
## See Also
210
-
[C++ Standard Library Overview](../standard-library/cpp-standard-library-overview.md)
210
+
[C++ Standard Library Overview](../standard-library/cpp-standard-library-overview.md)
Copy file name to clipboardExpand all lines: docs/standard-library/has-iterator-debugging.md
+6-5Lines changed: 6 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -34,22 +34,23 @@ translation.priority.ht:
34
34
- "zh-cn"
35
35
- "zh-tw"
36
36
---
37
-
# _HAS_ITERATOR_DEBUGGING
38
-
Defines whether the iterator debugging feature is enabled in a debug build. By default, iterator debugging is enabled in Debug builds and disabled in Retail builds. For more information, see [Debug Iterator Support](../standard-library/debug-iterator-support.md).
37
+
# _HAS_ITERATOR_DEBUGGING
38
+
39
+
Superseded by [_ITERATOR_DEBUG_LEVEL](../standard-library/iterator-debug-level.md), this macro defines whether the iterator debugging feature is enabled in a debug build. By default, iterator debugging is enabled in Debug builds and disabled in Retail builds. For more information, see [Debug Iterator Support](../standard-library/debug-iterator-support.md).
39
40
40
41
> [!IMPORTANT]
41
42
> Direct use of the `_HAS_ITERATOR_DEBUGGING` macro is deprecated. Instead, use `_ITERATOR_DEBUG_LEVEL` to control iterator debug settings. For more information, see [_ITERATOR_DEBUG_LEVEL](../standard-library/iterator-debug-level.md).
42
43
43
44
## Remarks
44
-
To enable iterator debugging in debug builds, set `_ITERATOR_DEBUG_LEVEL` to 2. This implies a `_HAS_ITERATOR_DEBUGGING` setting of 1, or enabled:
45
+
To enable iterator debugging in debug builds, set `_ITERATOR_DEBUG_LEVEL` to 2. This is equivalent to a `_HAS_ITERATOR_DEBUGGING` setting of 1, or enabled:
45
46
46
47
```
47
48
#define _ITERATOR_DEBUG_LEVEL 2
48
49
```
49
50
50
-
`_ITERATOR_DEBUG_LEVEL` cannot be set to 2 and `_HAS_ITERATOR_DEBUGGING` cannot be set to 1 in retail builds.
51
+
`_ITERATOR_DEBUG_LEVEL` cannot be set to 2 (and `_HAS_ITERATOR_DEBUGGING` cannot be set to 1) in retail builds.
51
52
52
-
To disable debug iterators in debug builds, set `_ITERATOR_DEBUG_LEVEL` to 0 or 1. This implies a `_HAS_ITERATOR_DEBUGGING` setting of 0, or disabled:
53
+
To disable debug iterators in debug builds, set `_ITERATOR_DEBUG_LEVEL` to 0 or 1. This is equivalent to a `_HAS_ITERATOR_DEBUGGING` setting of 0, or disabled:
Copy file name to clipboardExpand all lines: docs/standard-library/secure-scl.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -36,20 +36,20 @@ translation.priority.ht:
36
36
---
37
37
# _SECURE_SCL
38
38
39
-
Defines whether [Checked Iterators](../standard-library/checked-iterators.md) are enabled. By default, checked iterators are enabled in Debug builds, and disabled in Retail builds.
39
+
Superseded by [_ITERATOR_DEBUG_LEVEL](../standard-library/iterator-debug-level.md), this macro defines whether [Checked Iterators](../standard-library/checked-iterators.md) are enabled. By default, checked iterators are enabled in Debug builds, and disabled in Retail builds.
40
40
41
41
> [!IMPORTANT]
42
42
> Direct use of the `_SECURE_SCL` macro is deprecated. Instead, use `_ITERATOR_DEBUG_LEVEL` to control checked iterator settings. For more information, see [_ITERATOR_DEBUG_LEVEL](../standard-library/iterator-debug-level.md).
43
43
44
44
## Remarks
45
45
46
-
When checked iterators are enabled, unsafe iterator use causes a runtime error and the program is terminated. To enable checked iterators, set `_ITERATOR_DEBUG_LEVEL` to 1 or 2. This implies a `_SECURE_SCL` setting of 1, or enabled:
46
+
When checked iterators are enabled, unsafe iterator use causes a runtime error and the program is terminated. To enable checked iterators, set `_ITERATOR_DEBUG_LEVEL` to 1 or 2. This is equivalent to a `_SECURE_SCL` setting of 1, or enabled:
47
47
48
48
```
49
49
#define _ITERATOR_DEBUG_LEVEL 1
50
50
```
51
51
52
-
To disable checked iterators, set `_ITERATOR_DEBUG_LEVEL` to 0. This implies a `_SECURE_SCL` setting of 0, or disabled:
52
+
To disable checked iterators, set `_ITERATOR_DEBUG_LEVEL` to 0. This is equivalent to a `_SECURE_SCL` setting of 0, or disabled:
0 commit comments