Skip to content

Commit 1553cdd

Browse files
author
mikeblome
committed
Merge branch 'mb-dataindex' of github.com:Microsoft/vcppdocs into mb-dataindex
syncing with remote
2 parents 9787bd8 + 8fd8359 commit 1553cdd

19 files changed

+204
-52
lines changed

docs/cpp/attributes2.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: "Attributes2 | Microsoft Docs"
2+
title: "C++ Standard Attributes | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "11/04/2016"
4+
ms.date: "03/28/2017"
55
ms.reviewer: ""
66
ms.suite: ""
77
ms.tgt_pltfrm: ""
@@ -10,22 +10,21 @@ ms.assetid: 748340d9-8abf-4940-b0a0-91b6156a3ff8
1010
caps.latest.revision: 11
1111
manager: "ghogen"
1212
---
13-
# Attributes
13+
# C++ Standard Attributes
1414
In C++11, attributes provide a standardized way to annotate C++ constructs (including but not limited to classes, functions, variables, and blocks) with additional information that may or may not be vendor-specific. A compiler can use this information to generate informational messages, or to apply special logic when compiling the attributed code. The compiler ignores any attributes that it does not recognize, which means that you cannot define your own custom attributes using this syntax. Attributes are enclosed by double square brackets:
1515

1616
```
1717
[[deprecated]]
18-
void Foo(int);
19-
18+
void Foo(int);
2019
```
2120

22-
Attributes represent a standardized alternative to vendor-specific extensions such as #pragma directives, __declspec() (Visual C++), or \__attribute\_\_ (GNU). However, you will still need to use the vendor-specific constructs for most purposes. The standard currently specifies three attributes that a conforming compiler should recognize:
21+
Attributes represent a standardized alternative to vendor-specific extensions such as #pragma directives, __declspec() (Visual C++), or \__attribute\_\_ (GNU). However, you will still need to use the vendor-specific constructs for most purposes. The standard currently specifies three attributes that a conforming compiler should recognize:
2322

2423
- `noreturn` -- specifies that a function never returns; in other words it always throws an exception. The compiler can adjust its compilation rules for [[noreturn]] entities.
2524

26-
- `carries_dependency`--specifies that the function propagates data dependency ordering with respect to thread synchronization. The attribute can be applied to one or more parameters, to specify that the passed-in argument carries a dependency into the function body. The attribute can be applied to the function itself, to specify that the return value carries a dependency out of the function. The compiler can use this information to generate more efficient code.
25+
- `carries_dependency`--specifies that the function propagates data dependency ordering with respect to thread synchronization. The attribute can be applied to one or more parameters, to specify that the passed-in argument carries a dependency into the function body. The attribute can be applied to the function itself, to specify that the return value carries a dependency out of the function. The compiler can use this information to generate more efficient code.
2726

28-
- `deprecated` – specifies that a function is not intended to be used, and might not exist in future versions of a library interface. The compiler can use this to generate an informational message when client code attempts to call the function. Can be applied to declaration of a class, a typedef-name, a variable, a non-static data member, a function, a namespace, an enumeration, an enumerator, or a template specialization.
27+
- `deprecated`**Visual Studio 2015 and later:** specifies that a function is not intended to be used, and might not exist in future versions of a library interface. The compiler can use this to generate an informational message when client code attempts to call the function. Can be applied to declaration of a class, a typedef-name, a variable, a non-static data member, a function, a namespace, an enumeration, an enumerator, or a template specialization.
2928

3029
- `fallthrough` - **Visual Studio 2017 and later:**(available with [/std:c++latest](../build/reference/std-specify-language-standard-version.md)) The `[[fallthrough]]` attribute can be used in the context of [switch](switch-statement-cpp.md) statements as a hint to the compiler (or anyone reading the code) that the fallthrough behavior is intended. The Visual C++ compiler currently does not warn on fallthrough behavior, so this attribute has no effect compiler behavior.
3130

@@ -48,12 +47,12 @@ void Foo(int);
4847

4948
The example raises these warnings:
5049

51-
- 26494 (Type Rule 5: Always initialize an object.)
50+
- 26494 (Type Rule 5: Always initialize an object.)
5251

53-
- 26485 (Bounds Rule 3: No array to pointer decay.)
52+
- 26485 (Bounds Rule 3: No array to pointer decay.)
5453

55-
- 26481 (Bounds Rule 1: Don't use pointer arithmetic. Use span instead.)
54+
- 26481 (Bounds Rule 1: Don't use pointer arithmetic. Use span instead.)
5655

57-
The first two warnings fire when you compile this code with the CppCoreCheck code analysis tool installed and activated. But the third warning doesn't fire because of the attribute. You can suppress the entire bounds profile by writing [[gsl::suppress(bounds)]] without including a specific rule number. The C++ Core Guidelines are designed to help you write better and safer code. The suppress attribute makes it easy to turn off the warnings when they are not wanted.
56+
The first two warnings fire when you compile this code with the CppCoreCheck code analysis tool installed and activated. But the third warning doesn't fire because of the attribute. You can suppress the entire bounds profile by writing [[gsl::suppress(bounds)]] without including a specific rule number. The C++ Core Guidelines are designed to help you write better and safer code. The suppress attribute makes it easy to turn off the warnings when they are not wanted.
5857

5958
The C++ standard allows compiler vendors to define their own attribute parameters (within a vendor-specific namespace), but compilers are required to recognize only those attributes defined in the standard. In Visual C++, you can use the [[deprecated]] attribute instead of using declspec (deprecated) and the attribute will be recognized by any conformant compiler. For all other declspec parameters such as dllimport and dllexport, there is as yet no standard attribute equivalent so you must continue to use declspec syntax. Attributes do not affect the type system, and they don’t change the meaning of a program. Compilers ignore attribute values they don't recognize.

docs/cpp/decltype-cpp.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ decltype(auto) myFunc(T&& t, U&& u)
124124
## Example
125125
The following code example declares the late-specified return type of template function `Plus()`. The `Plus` function processes its two operands with the `operator+` overload. Consequently, the interpretation of the plus operator (+) and the return type of the `Plus` function depends on the types of the function arguments.
126126

127-
```
127+
```cpp
128128
// decltype_1.cpp
129129
// compile with: /EHsc
130130
//
@@ -200,6 +200,30 @@ int main()
200200
201201
42
202202
203+
## Example
204+
**Visual Studio 2017 and later:** The compiler parses decltype arguments when the templates are declared rather than instantiated. Consequently, if a non-dependent specialization is found in the decltype argument, it will not be deferred to instantiation-time and will be processed immediately and any resulting errors will be diagnosed at that time.
205+
206+
The following example shows such a compiler error that is raised at the point of declaration:
207+
208+
```cpp
209+
#include <utility>
210+
template <class T, class ReturnT, class... ArgsT> class IsCallable
211+
{
212+
public:
213+
struct BadType {};
214+
template <class U>
215+
static decltype(std::declval<T>()(std::declval<ArgsT>()...)) Test(int); //C2064. Should be declval<U>
216+
template <class U>
217+
static BadType Test(...);
218+
static constexpr bool value = std::is_convertible<decltype(Test<T>(0)), ReturnT>::value;
219+
};
220+
221+
constexpr bool test1 = IsCallable<int(), int>::value;
222+
static_assert(test1, "PASS1");
223+
constexpr bool test2 = !IsCallable<int*, int>::value;
224+
static_assert(test2, "PASS2");
225+
```
226+
203227
## Requirements
204228
Visual C++ 2010 or later versions.
205229

docs/cpp/deprecated-cpp.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "deprecated (C++) | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "11/04/2016"
4+
ms.date: "03/28/2017"
55
ms.reviewer: ""
66
ms.suite: ""
77
ms.technology:
@@ -37,15 +37,17 @@ translation.priority.ht:
3737
- "zh-tw"
3838
---
3939
# deprecated (C++)
40-
(Microsoft specific) With the exceptions noted below, the **deprecated** declaration offers the same functionality as the [deprecated](../preprocessor/deprecated-c-cpp.md) pragma:
40+
This topic is about the Microsoft-specific deprecated declspec declaration. For information about the C++14 `[[deprecated]]` attribute, and guidance on when to use that attribute vs. the Microsoft-specific declspec or pragma, see [C++ Standard Attributes](attributes2.md).
41+
42+
With the exceptions noted below, the **deprecated** declaration offers the same functionality as the [deprecated](../preprocessor/deprecated-c-cpp.md) pragma:
4143

4244
- The **deprecated** declaration lets you specify particular forms of function overloads as deprecated, whereas the pragma form applies to all overloaded forms of a function name.
4345

4446
- The **deprecated** declaration lets you specify a message that will display at compile time. The text of the message can be from a macro.
4547

4648
- Macros can only be marked as deprecated with the **deprecated** pragma.
4749

48-
If the compiler encounters the use of a deprecated identifier, a [C4996](../error-messages/compiler-warnings/compiler-warning-level-3-c4996.md) warning is thrown.
50+
If the compiler encounters the use of a deprecated identifier or the standard [`[[deprecated]]`](attributes2.md) attribute, a [C4996](../error-messages/compiler-warnings/compiler-warning-level-3-c4996.md) warning is thrown.
4951

5052
## Example
5153
The following sample shows how to mark functions as deprecated, and how to specify a message that will be displayed at compile time, when the deprecated function is used.

docs/cpp/static-assert.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ translation.priority.ht:
4040
- "zh-tw"
4141
---
4242
# static_assert
43-
Tests a software assertion at compile time. If the specified constant expression is `false`, the compiler displays the specified message and the compilation fails with error C2338; otherwise, the declaration has no effect.
43+
Tests a software assertion at compile time. If the specified constant expression is `false`, the compiler displays the specified message, if one is provided, and the compilation fails with error C2338; otherwise, the declaration has no effect.
4444

4545
## Syntax
4646

47-
```
48-
static_assert(
49-
constant-expression,
50-
string-literal
51-
);
47+
```
48+
static_assert( constant-expression, string-literal );
49+
50+
**Visual Studio 2017 and later:**
51+
static_assert( constant-expression );
5252
```
5353

5454
#### Parameters
@@ -59,7 +59,7 @@ static_assert(
5959
|`string-literal`|An message that is displayed if the `constant-expression` parameter is zero. The message is a string of characters in the [base character set](../c-language/ascii-character-set.md) of the compiler; that is, not [multibyte or wide characters](../c-language/multibyte-and-wide-characters.md).|
6060

6161
## Remarks
62-
The `constant-expression` parameter of a `static_assert` declaration represents a *software assertion*. A software assertion specifies a condition that you expect to be true at a particular point in your program. If the condition is true, the `static_assert` declaration has no effect. If the condition is false, the assertion fails, the compiler displays the message in `string-literal` parameter, and the compilation fails with an error.
62+
The `constant-expression` parameter of a `static_assert` declaration represents a *software assertion*. A software assertion specifies a condition that you expect to be true at a particular point in your program. If the condition is true, the `static_assert` declaration has no effect. If the condition is false, the assertion fails, the compiler displays the message in `string-literal` parameter, and the compilation fails with an error. In Visual Studio 2017 and later, the string-literal parameter is optional.
6363

6464
The `static_assert` declaration tests a software assertion at compile time. In contrast, the [assert Macro, _assert, _wassert](../c-runtime-library/reference/assert-macro-assert-wassert.md) macro tests a software assertion at run time and incurs a run time cost in space or time. The `static_assert` declaration is especially useful for debugging templates because template arguments can be included in the `constant-expression` parameter.
6565

docs/error-messages/compiler-errors-1/compiler-error-c2440.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Compiler Error C2440 | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "11/04/2016"
4+
ms.date: "03/28/2017"
55
ms.reviewer: ""
66
ms.suite: ""
77
ms.technology:
@@ -251,3 +251,48 @@ int main()
251251
This error can appear in ATL code that uses the SINK_ENTRY_INFO macro defined in <atlcom.h>.
252252
253253
```
254+
255+
## Example
256+
### Copy-list-initialization
257+
258+
Visual Studio 2017 and later correctly raise compiler errors related to object creation using initializer lists that were not caught in Visual Studio 2015 and could lead to crashes or undefined runtime behavior. As per N4594 13.3.1.7p1, in copy-list-initialization, the compiler is required to consider an explicit constructor for overload resolution, but must raise an error if that overload is actually chosen.
259+
The following two examples compile in Visual Studio 2015 but not in Visual Studio 2017.
260+
261+
```
262+
struct A
263+
{
264+
explicit A(int) {}
265+
A(double) {}
266+
};
267+
268+
int main()
269+
{
270+
A a1 = { 1 }; // error C3445: copy-list-initialization of 'A' cannot use an explicit constructor
271+
const A& a2 = { 1 }; // error C2440: 'initializing': cannot convert from 'int' to 'const A &'
272+
273+
}
274+
```
275+
276+
To correct the error, use direct initialization:
277+
278+
```
279+
A a1{ 1 };
280+
const A& a2{ 1 };
281+
```
282+
283+
## Example
284+
### cv-qualifiers in class construction
285+
286+
In Visual Studio 2015, the compiler sometimes incorrectly ignores the cv-qualifier when generating a class object via a constructor call. This can potentially cause a crash or unexpected runtime behavior. The following example compiles in Visual Studio 2015 but raises a compiler error in Visual Studio 2017 and later:
287+
288+
```
289+
struct S
290+
{
291+
S(int);
292+
operator int();
293+
};
294+
295+
int i = (const S)0; // error C2440
296+
```
297+
298+
To correct the error, declare operator int() as const.

docs/error-messages/compiler-errors-2/compiler-error-c2668.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Compiler Error C2668 | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "11/04/2016"
4+
ms.date: "03/28/2017"
55
ms.reviewer: ""
66
ms.suite: ""
77
ms.technology:
@@ -153,4 +153,26 @@ int main() {
153153
pow(9,9); // C2668
154154
pow((double)9,9); // OK
155155
}
156+
```
157+
158+
## Example
159+
This code succeeds in Visual Studio 2015 but fails in Visual Studio 2017 and later with C2668. In Visual Studio 2015, the compiler erroneously treated copy-list-initialization in the same way as regular copy-initialization; it considered only converting constructors for overload resolution.
160+
161+
```
162+
C++
163+
struct A {
164+
explicit A(int) {}
165+
};
166+
167+
struct B {
168+
B(int) {}
169+
};
170+
171+
void f(const A&) {}
172+
void f(const B&) {}
173+
174+
int main()
175+
{
176+
f({ 1 }); // error C2668: 'f': ambiguous call to overloaded function
177+
}
156178
```

docs/error-messages/compiler-errors-2/compiler-error-c2955.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Compiler Error C2955 | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "11/04/2016"
4+
ms.date: "03/28/2017"
55
ms.reviewer: ""
66
ms.suite: ""
77
ms.technology:
@@ -87,4 +87,16 @@ int main() {
8787
GC^ g; // C2955
8888
GC <int>^ g;
8989
}
90-
```
90+
```
91+
92+
## Example
93+
**Visual Studio 2017 and later:** The compiler correctly diagnoses missing template argument lists when the template appears in a template parameter list (for example as part of a default template argument or a non-type template parameter). The following code compiles in Visual Studio 2015 but produces an error in Visual Studio 2017.
94+
95+
```
96+
template <class T> class ListNode;
97+
template <class T> using ListNodeMember = ListNode<T> T::*;
98+
template <class T, ListNodeMember M> class ListHead; // C2955: 'ListNodeMember': use of alias
99+
// template requires template argument list
100+
101+
// correct: template <class T, ListNodeMember<T> M> class ListHead;
102+
```

docs/error-messages/compiler-errors-2/compiler-error-c3066.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Compiler Error C3066 | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "11/04/2016"
4+
ms.date: "03/28/2017"
55
ms.reviewer: ""
66
ms.suite: ""
77
ms.technology:
@@ -71,4 +71,28 @@ int main() {
7171
a(&i, &c); // C3066
7272
a(&i, (const char *) &c); // OK
7373
}
74+
```
75+
76+
## Copy-list-initialization
77+
In Visual Studio 2015, the compiler erroneously treated copy-list-initialization in the same way as regular copy-initialization; it considered only converting constructors for overload resolution. In the following example, Visual Studio 2015 chooses MyInt(23) but Visual Studio 2017 correctly raises the error.
78+
79+
```
80+
// From http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#1228
81+
struct MyList {
82+
explicit MyStore(int initialCapacity);
83+
};
84+
85+
struct MyInt {
86+
MyInt(int i);
87+
};
88+
89+
struct Printer {
90+
void operator()(MyStore const& s);
91+
void operator()(MyInt const& i);
92+
};
93+
94+
void f() {
95+
Printer p;
96+
p({ 23 }); // C3066: there are multiple ways that an object of this type can be called with these arguments
97+
}
7498
```

docs/error-messages/compiler-warnings/compiler-warning-level-3-c4996.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ The compiler encountered a deprecated declaration.
4040

4141
This warning or error has several possible meanings.
4242

43-
`C4996` occurs when the compiler encounters a function or variable that is marked as [deprecated](../../cpp/deprecated-cpp.md). Several functions, member functions, template functions, and global variables in the libraries in Visual Studio are marked as deprecated. These functions may have a different preferred name, may be insecure or have a more secure variant, or may be obsolete. The error message may include a suggested replacement for the deprecated function or global variable. You can turn this warning off with the [warning](../../preprocessor/warning.md) pragma or the **/wd4996** command line option. You can also use preprocessor macros to turn off certain classes of deprecation warnings.
43+
`C4996` occurs when the compiler encounters a function or variable that is marked as [deprecated](../../cpp/deprecated-cpp.md). Several functions, member functions, template functions, and global variables in the libraries in Visual Studio are marked as deprecated. These functions may have a different preferred name, may be insecure or have a more secure variant, or may be obsolete. The error message may include a suggested replacement for the deprecated function or global variable. You can turn this warning off with the [warning](../../preprocessor/warning.md) pragma or the **/wd4996** command line option. You can also use preprocessor macros to turn off certain classes of deprecation warnings.
44+
45+
This warning is also issued when you attempt to access a function, class member or typedef that has the C++14 `[[deprecated]]` attribute. For more information, see [C++ Standard Attributes](../../cpp/attributes2.md).
4446

4547
**The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name:** new_name**. See online help for details.**
4648

docs/mfc/reference/cmap-class.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,9 @@ CPair *PGetNextAssoc(const CPair* pAssocRet);
374374
Finds the value mapped to a given key.
375375

376376
```
377-
const CPair* PLookup(ARG_KEY key) const;
378-
CPair* PLookup(Â ARG_KEY keyÂ); ```
377+
const CPair* PLookup(ARG_KEY key) const;
378+
CPair* PLookup(ARG_KEY key);
379+
```
379380

380381
### Parameters
381382
`key`

0 commit comments

Comments
 (0)