Skip to content

Commit e65e3df

Browse files
author
Colin Robertson
authored
Merge pull request MicrosoftDocs#2375 from JordanMaples/patch-4
C26498 - Description & Examples
2 parents ce5440d + 6fdce6d commit e65e3df

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

docs/code-quality/c26498.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
11
---
22
title: C26498
3-
ms.date: 03/22/2018
3+
ms.date: 08/18/2020
44
ms.topic: reference
55
f1_keywords: ["C26498"]
66
helpviewer_keywords: ["C26498"]
77
---
88
# C26498 USE_CONSTEXPR_FOR_FUNCTIONCALL
99

10-
This function call %function% can use `constexpr` if compile-time evaluation is desired. See [C++ Core Guidelines con.5](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rconst-constexpr).
10+
This rule helps to enforce Con.5 from the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#con5-use-constexpr-for-values-that-can-be-computed-at-compile-time): use constexpr for values that can be computed at compile time.
11+
12+
## Remarks
13+
14+
The warning is triggered by assigning the result of a **`constexpr`** function to any non-**`constexpr`** variable whose value doesn't change after the initial assignment.
15+
16+
## Example
17+
18+
This sample code shows where C26498 may appear, and how to avoid it:
19+
20+
```cpp
21+
constexpr int getMyValue()
22+
{
23+
return 1;
24+
}
25+
26+
void foo()
27+
{
28+
constexpr int val0 = getMyValue(); // no C26498
29+
const int val1 = getMyValue(); // C26498, C26814
30+
int val2 = getMyValue(); // C26498, value is never modified
31+
int val3 = getMyValue(); // no C26498, val3 is assigned to below.
32+
val3 = val3 * val2;
33+
}
34+
```
35+

0 commit comments

Comments
 (0)