Skip to content

Commit 4aa9f59

Browse files
author
Colin Robertson
authored
Update c26432.md
Add a reason for defining some SMFs and deleting others.
1 parent c235ef1 commit 4aa9f59

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

docs/code-quality/c26432.md

+13-9
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,33 @@ Special operations such as constructors are assumed to alter the behavior of typ
3030

3131
## Example
3232

33-
In this example, `warning::S` defines only a default constructor and a destructor. The `no_warning::S` declaration defines all five special member functions.
33+
In this example, `warning::S` defines only a default constructor and a destructor. The `no_warning::S` declaration defines or deletes all five special member functions.
3434

3535
```cpp
3636
// C26432.cpp
3737
namespace warning
3838
{
3939
struct S
4040
{
41-
S() noexcept {}
42-
~S() {} // C26432 because only the constructor and destructor are explicitly defined.
41+
S() noexcept { ++_count; }
42+
~S() { --_count; } // C26432 because only the constructor and destructor are explicitly defined.
43+
static unsigned _count;
4344
};
45+
unsigned S::_count = 0;
4446
}
4547

4648
namespace no_warning
4749
{
4850
struct S
4951
{
50-
S() noexcept = default;
51-
S(const S& s) = default;
52-
S(S&& s) = default;
53-
S& operator=(const S& s) = default;
54-
S& operator=(S&& s) = default;
55-
~S() = default;
52+
S() noexcept { _count++; }
53+
S(const S& s) = delete;
54+
S(S&& s) = delete;
55+
S& operator=(const S& s) = delete;
56+
S& operator=(S&& s) = delete;
57+
~S() { --_count; }
58+
static unsigned _count;
5659
};
60+
unsigned S::_count = 0;
5761
}
5862
```

0 commit comments

Comments
 (0)