Skip to content

Commit 6ee588a

Browse files
authored
C26498
Replacing the placeholder description and providing examples.
1 parent c6184f0 commit 6ee588a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

docs/code-quality/c26498.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,24 @@ 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+
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.
13+
14+
# Example
15+
```cpp
16+
constexpr int getMyValue()
17+
{
18+
return 1;
19+
}
20+
21+
void foo()
22+
{
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+
}
29+
```
30+

0 commit comments

Comments
 (0)