Skip to content

Commit 6fdce6d

Browse files
author
Colin Robertson
authored
Date, style updates
1 parent 6ee588a commit 6fdce6d

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

docs/code-quality/c26498.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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"]
@@ -9,22 +9,27 @@ helpviewer_keywords: ["C26498"]
99

1010
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.
1111

12-
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.
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:
1319

14-
# Example
1520
```cpp
1621
constexpr int getMyValue()
1722
{
18-
return 1;
23+
return 1;
1924
}
2025

2126
void foo()
2227
{
23-
constexpr int val0 = getMyValue(); // no C26498
24-
const int val1 = getMyValue(); // C26498, C26814
25-
int val2 = getMyValue(); // C26498, value is never modified
26-
int val3 = getMyValue(); // no C26498, val3 is assigned to below.
27-
val3 = val3 * val2;
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;
2833
}
2934
```
3035

0 commit comments

Comments
 (0)