Skip to content

Commit 711b9e8

Browse files
authored
Merge branch 'master' into mblome-cx2
2 parents c0f314a + 2e4837d commit 711b9e8

14 files changed

+937
-269
lines changed

docs/TOC.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# [Visual C++ in Visual Studio 2017 RC](visual-cpp-in-visual-studio.md)
2-
# [What's New for Visual C++ in Visual Studio 2017 RC](what-s-new-for-visual-cpp-in-visual-studio.md)
1+
# [Visual C++ in Visual Studio 2017](visual-cpp-in-visual-studio.md)
2+
# [What's New for Visual C++ in Visual Studio 2017](what-s-new-for-visual-cpp-in-visual-studio.md)
33
# [C++ conformance improvements in Visual Studio 2017](cpp-conformance-improvements-2017.md)
44
## [Visual C++ Language Conformance](visual-cpp-language-conformance.md)
55
# [Supported Platforms (Visual C++)](supported-platforms-visual-cpp.md)

docs/cpp/constexpr-cpp.md

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ translation.priority.ht:
3434
- "zh-tw"
3535
---
3636
# constexpr (C++)
37-
The keyword `constexpr` was introduced in C++11 and improved in C++14. It means *constant expression*. Like `const`, it can be applied to variables so that a compiler error will be raised if any code attempts to modify the value. Unlike `const`, `constexpr` can also be applied to functions and class constructors. `constexpr` indicates that the value, or return value, is constant and, if possible, will be computed at compile time. A `constexpr` integral value can be used wherever a const integer is required, such as in template arguments and array declarations. And when a value can be computed at compile time instead of run time, it can help your program can run faster and use less memory.
37+
The keyword `constexpr` was introduced in C++11 and improved in C++14. It means *constant expression*. Like `const`, it can be applied to variables so that a compiler error will be raised if any code attempts to modify the value. Unlike `const`, `constexpr` can also be applied to functions and class constructors. `constexpr` indicates that the value, or return value, is constant and, if possible, will be computed at compile time. A `constexpr` integral value can be used wherever a const integer is required, such as in template arguments and array declarations. And when a value can be computed at compile time instead of run time, it can help your program run faster and use less memory.
3838

3939
## Syntax
4040

4141
```cpp
42-
constexpr literal-type identifier = constant-expression;constexpr literal-type identifier { constant-expression };constexpr literal-type identifier(params );constexpr ctor (params);
42+
constexpr literal-type identifier = constant-expression;
43+
constexpr literal-type identifier { constant-expression };
44+
constexpr literal-type identifier(params );
45+
constexpr ctor (params);
4346
```
4447
4548
#### Parameters
@@ -64,8 +67,18 @@ constexpr literal-type identifier = constant-expression;constexpr literal-typ
6467
6568
## constexpr variables
6669
The primary difference between const and constexpr variables is that the initialization of a const variable can be deferred until run time whereas a constexpr variable must be initialized at compile time. All constexpr variables are const.
70+
71+
- A variable can be declared with `constexpr`, if it has a literal type and is initialized. If the initialization is performed by a constructor, the constructor must be declared as `constexpr`.
6772
68-
```
73+
- A reference may be declared as constexpr if the object that it references has been initialized by a constant expression and any implicit conversions that are invoked during initialization are also constant expressions.
74+
75+
- All declarations of a `constexpr` variable or function must have the `constexpr` specifier.
76+
77+
78+
79+
80+
81+
```cpp
6982
constexpr float x = 42.0;
7083
constexpr float y{108};
7184
constexpr float z = exp(5, 3);
@@ -75,9 +88,38 @@ constexpr int k = j + 1; //Error! j not a constant expression
7588
```
7689

7790
## constexpr functions
78-
A `constexpr` function is one whose return value can be computed at compile when consuming code requires it. A `constexpr` function must accept and return only literal types. When its arguments are `constexpr` values, and consuming code requires the return value at compile time, for example to initialize a `constexpr` variable or provide a non-type template argument, it produces a compile-time constant. When called with non-`constexpr` arguments, or when its value is not required at compile-time, it produces a value at run time like a regular function. (This dual behavior saves you from having to write `constexpr` and non-`constexpr` versions of the same function.)
91+
A `constexpr` function is one whose return value can be computed at compile when consuming code requires it. When its arguments are `constexpr` values, and consuming code requires the return value at compile time, for example to initialize a `constexpr` variable or provide a non-type template argument, it produces a compile-time constant. When called with non-`constexpr` arguments, or when its value is not required at compile-time, it produces a value at run time like a regular function. (This dual behavior saves you from having to write `constexpr` and non-`constexpr` versions of the same function.)
92+
93+
A `constexpr` function or constructor is implicitly `inline`.
94+
95+
The following rules apply to constexpr functions:
96+
97+
- A `constexpr` function must accept and return only literal types.
98+
99+
- A `constexpr` function can be recursive.
100+
101+
- It cannot be [virtual](../cpp/virtual-cpp.md). A a constructor cannot be defined as constexpr if the enclosing class has any virtual base classes.
102+
103+
- The body can be defined as `= default` or `= delete`.
104+
105+
- The body can contain no `goto` statements or try blocks.
106+
107+
- An explicit specialization of a non-constexpr template can be declared as `constexpr`:
108+
109+
- An explicit specialization of a `constexpr` template does not have to also be `constexpr`:
110+
111+
112+
<!--conformance note-->
113+
The following rules apply to constexpr functions in Visual Studio 2017 and later:
114+
115+
- It may contain if and switch statements, and all looping statements including for, range-based for, while, and do-while
116+
117+
- It may contain local variable declarations, but the variable must be initialized, must be a literal type, and cannot be static or thread-local. The locally-declared variable is not required to be const and may mutate.
118+
119+
- A constexpr non-static member function is not required to be implicitly const.
120+
79121

80-
```
122+
```cpp
81123
constexpr float exp(float x, int n)
82124
{
83125
return n == 0 ? 1 :
@@ -89,23 +131,7 @@ constexpr float exp(float x, int n)
89131
> [!TIP]
90132
> Note: In the Visual Studio debugger, you can tell whether a `constexpr` function is being evaluated at compile time by putting a breakpoint inside it. If the breakpoint is hit, the function was called at run-time. If not, then the function was called at compile time.
91133
92-
## General constexpr rules
93-
For a function, variable, constructor or static data member to be defined as `constexpr`, it must meet certain requirements:
94-
95-
- A `constexpr` function can be recursive. It cannot be [virtual](../cpp/virtual-cpp.md), and its return type and parameter types must all be literal types. The body can be defined as `= default` or `= delete`. Otherwise it must follow these rules: it contains no `goto` statements, try blocks, unitialized variables, or variable definitions that are not literal types, or that are static or thread-local. Additionally, a constructor cannot be defined as constexpr if the enclosing class has any virtual base classes.
96-
97-
- A variable can be declared with `constexpr`, if it has a literal type and is initialized. If the initialization is performed by a constructor, the constructor must be declared as `constexpr`.
98-
99-
- A reference may be declared as constexpr if the object that it references has been initialized by a constant expression and any implicit conversions that are invoked during initialization are also constant expressions.
100-
101-
- All declarations of a `constexpr` variable or function must have the `constexpr` specifier.
102-
103-
- An explicit specialization of a non-constexpr template can be declared as `constexpr`:
104-
105-
- An explicit specialization of a `constexpr` template does not have to also be `constexpr`:
106-
107-
- A `constexpr` function or constructor is implicitly `inline`.
108-
134+
109135
## Example
110136
The following example shows `constexpr` variables, functions and a user-defined type. Note that in the last statement in main(), the `constexpr` member function GetValue() is a run-time call because the value is not required to be known at compile time.
111137
@@ -182,4 +208,4 @@ int main()
182208
183209
## See Also
184210
[Declarations and Definitions](../cpp/declarations-and-definitions-cpp.md)
185-
[const](../cpp/constexpr-cpp.md)
211+
[const](../cpp/const-cpp.md)

docs/cpp/initializers.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ int main() {
388388
389389
- no virtual member functions
390390
391-
- no brace-or-equal initializers for non-static members
391+
> [!NOTE]
392+
> <!--conformance note-->In Visual Studio 2015 and earlier, an aggregate is not allowed to have brace-or-equal initializers for non-static members. This restriction was removed in the C++14 standard and implemented in Visual Studio 2017.
392393
393394
Aggregate initializers consist of a braced initialization list, with or without an equals sign, as in the following example:
394395
@@ -435,7 +436,7 @@ myArr3: 8 9 10 0 0
435436
```
436437

437438
> [!IMPORTANT]
438-
> Array members that declared but not explicitly initialized during aggregate initialization are zero-initialized, as in `myArr3` above.
439+
> Array members that are declared but not explicitly initialized during aggregate initialization are zero-initialized, as in `myArr3` above.
439440

440441
#### Initializing unions and structs
441442
If a union does not have a constructor, you can initialize it with a single value (or with another instance of a union). The value is used to initialize the first non-static field. This is different from struct initialization, in which the first value in the initializer is used to initialize the first field, the second to initialize the second field, and so on. Compare the initialization of unions and structs in the following example:

docs/data/data-access-programming-mfc-atl.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ translation.priority.ht:
3939
# Data Access Programming (MFC/ATL)
4040
Over the years, Visual C++ has provided several ways to work with databases. In 2011 Microsoft announced that it is aligning on ODBC as the preferred technology for accessing SQL Server products from native code. ODBC is an industry standard, and by using it you gain maximum portability of your code over multiple platforms and data sources. Most SQL database products and many NoSQL products support ODBC. You can use ODBC directly by calling the low-level ODBC APIs, or you can use the MFC ODBC wrapper classes, or a third-party C++ wrapper library.
4141

42-
OLE DB is a low-level, high-performance API based on the COM specification, and is only supported on Windows. ATL provides OLE DB templates that make it easier to create custom OLE DB providers and consumers. OLE DB support in SQL Server products is officially deprecated and there is no guarantee that it will be supported after SQL Server 2016.
42+
OLE DB is a low-level, high-performance API based on the COM specification, and is only supported on Windows. Use OLE DB if your program is accessing [linked servers](https://msdn.microsoft.com/library/ms188279.aspx). ATL provides OLE DB templates that make it easier to create custom OLE DB providers and consumers. The most recent version of OLE DB shipped in SQL Native Client 11.
4343

44-
If your legacy application uses OLE DB or the higher-level ADO interface to connect to SQL Server, you should consider migrating to ODBC in the near future. If you do not require cross-platform portability or the latest SQL Server features, you can possibly use the Microsoft OLE DB Provider for ODBC (MSDASQL). MSDASQL allows applications that are built on OLEDB and ADO (which uses OLEDB internally) to access data sources through an ODBC driver. MSDASQL ships with the Windows operating system, and Windows Server 2008 & Windows Vista SP1 are the first Windows releases to include a 64-bit version of the technology.
44+
If your legacy application uses OLE DB or the higher-level ADO interface to connect to SQL Server, and you are not accessing linked servers, you should consider migrating to ODBC in the near future. If you do not require cross-platform portability or the latest SQL Server features, you can possibly use the Microsoft OLE DB Provider for ODBC (MSDASQL). MSDASQL allows applications that are built on OLE DB and ADO (which uses OLEDB internally) to access data sources through an ODBC driver. As with any translation layer, MSDASQL can impact database performace. You should test to determine whether the impact is signifant for your application. MSDASQL ships with the Windows operating system, and Windows Server 2008 & Windows Vista SP1 are the first Windows releases to include a 64-bit version of the technology.
4545

46-
The SQL Native Client component (SNAC), which packages OLE DB and ODBC drivers in a single DLL, is also deprecated for applications. The SQL Server 2012 version of SNAC ships with SQL Server 2016 because other SQL Server components depend on it. However, new C++ applications that connect to SQL Server or Azure SQL Database should use [the most recent ODBC driver](https://docs.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server). For more information, see [SQL Server Native Client Programming](https://msdn.microsoft.com/en-us/library/ms130892.aspx)
46+
The SQL Native Client component (SNAC), which packages OLE DB and ODBC drivers in a single DLL, is deprecated for ODBC applications. The SQL Server 2012 version of SNAC (SQLNCLI11.DLL) ships with SQL Server 2016 because other SQL Server components depend on it. However, new C++ applications that connect to SQL Server or Azure SQL Database via ODBC should use [the most recent ODBC driver](https://docs.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server). For more information, see [SQL Server Native Client Programming](https://msdn.microsoft.com/en-us/library/ms130892.aspx)
4747

4848
If you use C++/CLI, you can continue to use ADO.NET as always. For more information, see [Data Access Using ADO.NET (C++/CLI)](../dotnet/data-access-using-adonet-cpp-cli.md), and [Accessing data in Visual Studio](/visualstudio/data-tools/accessing-data-in-visual-studio).
4949

0 commit comments

Comments
 (0)