Skip to content

Commit 9e2bfb1

Browse files
author
Colin Robertson
authored
Fix more iterator SCL macro language (MicrosoftDocs#119)
* Fix more iterator SCL macro language * Missed a change.
1 parent 441f493 commit 9e2bfb1

File tree

4 files changed

+43
-42
lines changed

4 files changed

+43
-42
lines changed

docs/porting/visual-cpp-change-history-2003-2015.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2733,7 +2733,7 @@ When you upgrade to a new version of the Visual C++ compiler, you might encounte
27332733
27342734
- Support for Windows 95, Windows 98, Windows Millennium Edition, and Windows NT 4.0 has been removed.
27352735
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.
27372737
27382738
- The member variable c of the stack Class is now declared protected. Previously, this member variable was declared public.
27392739
@@ -2819,7 +2819,7 @@ When you upgrade to a new version of the Visual C++ compiler, you might encounte
28192819
28202820
- 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.
28212821
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)
28232823
28242824
## Visual C++ .NET 2003 Breaking Changes
28252825

docs/standard-library/debug-iterator-support.md

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ ms.technology:
88
- "devlang-cpp"
99
ms.tgt_pltfrm: ""
1010
ms.topic: "article"
11-
f1_keywords:
12-
- "_HAS_ITERATOR_DEBUGGING symbol"
1311
dev_langs:
1412
- "C++"
1513
helpviewer_keywords:
@@ -42,19 +40,20 @@ translation.priority.ht:
4240
- "zh-tw"
4341
---
4442
# 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).
4644

4745
The C++ standard describes how member functions might cause iterators to a container to become invalid. Two examples are:
4846

4947
- Erasing an element from a container causes iterators to the element to become invalid.
5048

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.
5250

5351
## 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.
5553

5654
```cpp
57-
/* compile with /EHsc /MDd */
55+
// iterator_debugging_0.cpp
56+
// compile by using /EHsc /MDd
5857
#include <vector>
5958
#include <iostream>
6059

@@ -71,24 +70,21 @@ int main() {
7170
std::vector<int>::iterator j = v.end();
7271
--j;
7372

74-
std::cout<<*j<<'\n';
73+
std::cout << *j << '\n';
7574

7675
v.insert(i,25);
7776

78-
std::cout<<*j<<'\n'; // Using an old iterator after an insert
77+
std::cout << *j << '\n'; // Using an old iterator after an insert
7978
}
8079
```
8180

8281
## 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.
8783

8884
```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
9288
#include <vector>
9389
#include <iostream>
9490

@@ -105,11 +101,11 @@ int main() {
105101
std::vector<int>::iterator j = v.end();
106102
--j;
107103

108-
std::cout<<*j<<'\n';
104+
std::cout << *j << '\n';
109105

110106
v.insert(i,25);
111107

112-
std::cout<<*j<<'\n'; // Using an old iterator after an insert
108+
std::cout << *j << '\n'; // Using an old iterator after an insert
113109
}
114110
```
115111

@@ -119,12 +115,14 @@ int main() {
119115
```
120116

121117
## 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:
123119

124120
```cpp
125-
/* compile with /EHsc /MDd */
121+
// iterator_debugging_2.cpp
122+
// compile by using: /EHsc /MDd
126123
#include <string>
127124
using namespace std;
125+
128126
int main() {
129127
string::iterator i1, i2;
130128
if (i1 == i2)
@@ -133,10 +131,11 @@ int main() {
133131
```
134132

135133
## 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.
137135

138136
```cpp
139-
/* compile with /EHsc /MDd */
137+
// iterator_debugging_3.cpp
138+
// compile by using /EHsc /MDd
140139
#include <algorithm>
141140
#include <vector>
142141
using namespace std;
@@ -152,20 +151,20 @@ int main()
152151
v2.push_back(10);
153152
v2.push_back(20);
154153

155-
// The next line will assert because v1 and v2 are
154+
// The next line asserts because v1 and v2 are
156155
// incompatible.
157156
for_each(v1.begin(), v2.end(), [] (int& elem) { elem *= 2; } );
158157
}
159158
```
160159

161-
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).
162161

163162
## 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.
165164

166165
```cpp
167-
// debug_iterator.cpp
168-
// compile with: /EHsc /MDd
166+
// iterator_debugging_4.cpp
167+
// compile by using: /EHsc /MDd
169168
#include <vector>
170169
#include <iostream>
171170
int main() {
@@ -175,20 +174,21 @@ int main() {
175174
v.push_back(15);
176175
v.push_back(20);
177176

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
180179
--i; // C2065
181180
}
182181
```
183182

184183
## 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:
186185

187186
```cpp
188-
/* compile with: /EHsc /MDd */
187+
// iterator_debugging_5.cpp
188+
// compile by using: /EHsc /MDd
189189
#include <vector>
190190
struct base {
191-
// FIX: uncomment the next line
191+
// TO FIX: uncomment the next line
192192
// virtual ~base() {}
193193
};
194194

@@ -207,7 +207,7 @@ int main() {
207207
```
208208
209209
## 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)
211211
212212
213213

docs/standard-library/has-iterator-debugging.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,23 @@ translation.priority.ht:
3434
- "zh-cn"
3535
- "zh-tw"
3636
---
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).
3940

4041
> [!IMPORTANT]
4142
> 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).
4243
4344
## 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:
4546

4647
```
4748
#define _ITERATOR_DEBUG_LEVEL 2
4849
```
4950

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.
5152

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:
5354

5455
```
5556
#define _ITERATOR_DEBUG_LEVEL 0

docs/standard-library/secure-scl.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ translation.priority.ht:
3636
---
3737
# _SECURE_SCL
3838

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.
4040

4141
> [!IMPORTANT]
4242
> 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).
4343
4444
## Remarks
4545

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:
4747

4848
```
4949
#define _ITERATOR_DEBUG_LEVEL 1
5050
```
5151

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:
5353

5454
```
5555
#define _ITERATOR_DEBUG_LEVEL 0

0 commit comments

Comments
 (0)