Skip to content

docs: rewrite Chapter 07 — Enums from C++98 to C++26 - #14

Merged
yuchdev merged 4 commits into
masterfrom
docs/rewrite-enums-cpp98-cpp26
Oct 22, 2026
Merged

yuchdev merged 4 commits into
masterfrom
docs/rewrite-enums-cpp98-cpp26

Conversation

@yuchdev

@yuchdev yuchdev commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Summary

Rewrite the enums chapter in the narrative technical-literature format used in Chapters 01–06, covering classic unscoped enums through C++26 static reflection.

Correctness fixes

  • Explain the distinct enum value range vs underlying representation, including undefined out-of-range conversions for non-fixed enums (CWG 1766).
  • Correct C++11 scoped enum default underlying type (int) and completeness of opaque enum declarations.
  • Update two existing example programs so that the chapter's code does not demonstrate undefined behavior as though it were harmless.

Expanded coverage

  • C++98 unscoped enums, integral promotion and overload resolution.
  • C++11 scoped/fixed-underlying enums, opaque declarations, value ranges, ABI.
  • C++17 direct-list initialization, C++20 using enum, C++23 std::to_underlying and std::is_scoped_enum.
  • Bitmask correctness, switch exhaustiveness, protocol validation, serialization, C interoperability, and enum state transitions.
  • C++26 static reflection via std::meta::enumerators_of with availability caveats.
  • Five standardized closing sections: rules, diagnostics, standards timeline, Java/Python/C# migration, and further reading.

Scope and validation

Changes only Chapter 07 README and two directly associated examples. Structurally checked the required ending order and code-fence balance. C++26 reflection example is illustrative and uncompiled; CI should validate the repository's C++20 baseline.

Copilot AI balanced review requested due to automatic review settings October 18, 2026 17:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Escaped Markdown delimiters break code-example rendering throughout the chapter.

3 open issues
What changed in this PR

Rewrites Chapter 07 as a narrative guide to enums from C++98 through C++26, connecting language rules to the course’s examples.

Changes:

  • Expands coverage of conversions, validation, bitmasks, ABI, and reflection.
  • Replaces an undefined conversion with a safe unnamed-value example.
  • Corrects opaque-enum completeness explanations and adds a compile-time assertion.
File Description
01_low_level/​07_enums/​README.md Rewrites and expands the enums chapter.
01_low_level/​07_enums/​02_enums_scoped/​enums_scoped.cpp Corrects completeness comments and asserts enum size.
01_low_level/​07_enums/​01_enums_core/​enums_core.cpp Demonstrates a safe, in-range unnamed enum value.

Review effort: Balanced

Comment thread 01_low_level/07_enums/README.md Outdated

Consider status and device-state values that happen to share their representation. There is no implicit assignment from one enum type to another, and this is intentional: the number alone does not define its meaning.

\`\`\`cpp

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the backslashes from the Markdown code and inline-code delimiters and repaired the enum class delimiter. Commit: 502defd.

Comment thread 01_low_level/07_enums/README.md Outdated

### Never use an out-of-range example as a harmless demonstration

The existing \`01_enums_core/enums_core.cpp\` example casts \`20\` to an enum whose enumerators are only \`0\` and \`1\`. Because that enum has no fixed underlying type, it is not a valid demonstration of merely holding an unnamed enum value. It needs correction in the accompanying source example as well as in this chapter.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the paragraph to describe the in-range unnamed value 3 in the corrected example and noted that the out-of-range cast remains only in a warning comment. Commit: 502defd.

Comment thread 01_low_level/07_enums/README.md Outdated
Co-authored-by: yuchdev <678436+yuchdev@users.noreply.github.com>
@yuchdev
yuchdev merged commit d41a1a6 into master Oct 22, 2026
4 checks passed
@yuchdev
yuchdev deleted the docs/rewrite-enums-cpp98-cpp26 branch October 22, 2026 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants