# C++에서 true의 보수는 true다 — 단, gcc에서는 false

Original title: The complement of true is true, except when it's false

> Hacker News story 49953344 · language: ko · submitted 2026-10-04
> Web version: https://zeli.app/ko/story/49953344
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 72 · by [aw1621107](<https://news.ycombinator.com/user?id=aw1621107>) · 💬 28
[original](<https://dryperspective.github.io/posts/complement-of-true/>) · [HN discussion](<https://news.ycombinator.com/item?id=49953344>)

## Summary

P4313R1은 C++26 어노테이션으로 enum에 비트마스크 연산을 추가하는 제안이다. 이를 계기로 C++ 정수 연산의 복잡한 이면을 살펴본다. bool은 정수 승격과 불리언 변환을 거치면서 ~true가 true가 되는 기이한 결과를 낳는다. gcc는 enum 기반 bool 타입에서 표준과 다르게 동작하는 오래된 버그를 가지고 있으며, 스코프 없는 enum의 비트 연산은 정의되지 않은 동작(UB)을 유발할 수 있다.

## Key quote

> true의 보수는 true다. C++로 쓰면 static_cast<bool>(~true) == true이다.

## HN discussion (28 comments)

### [Panzerschrek](<https://news.ycombinator.com/item?id=49978427>)

> 다음과 같은 예시가 있습니다:
>
> bool Complement( bool x )
>
> {
>
> return ~x;
>
> }
>
> GCC는 -Wall로 컴파일하면 경고를 줍니다:
>
> test.cpp:3:10: warning: ‘~’ on an expression of type bool [-Wbool-operation]
>
> return ~x;
>
> 그래서 C++가 이렇게 동작한다는 게 놀랍긴 하지만, 컴파일러 경고를 켜는 사람들은 곤란을 겪지 않습니다.

### [nine_k](<https://news.ycombinator.com/item?id=49979815>)

> C++는 어떤 면에서 Perl의 진정한 정신적 후계자입니다. 무엇이든 표현할 수 있고, 문법은 난해하며 논리도 그렇습니다. 물론 대부분의 경우 보이는 대로 얻지만, 보이는 것이 얻지 못하는 것이 되는 순간이 오기 전까지는요.

### [s-zeng](<https://news.ycombinator.com/item?id=49976943>)

> 특성 2인 체에서는 모든 원소가 자기 자신의 음수입니다. 따라서 직관에 반하는 enum의 예외적 동작에도 불구하고 표면적으로는 말이 됩니다.

---

## Cite

- Page: https://zeli.app/ko/story/49953344
- Date: 2026-10-04
- Source: dryperspective.github.io (https://dryperspective.github.io/posts/complement-of-true/)
- Hacker News: https://news.ycombinator.com/item?id=49953344

## Other languages

- en: https://zeli.app/story/49953344 · markdown: https://zeli.app/story/49953344.md
- zh: https://zeli.app/zh/story/49953344 · markdown: https://zeli.app/zh/story/49953344.md
- ja: https://zeli.app/ja/story/49953344 · markdown: https://zeli.app/ja/story/49953344.md
- de: https://zeli.app/de/story/49953344 · markdown: https://zeli.app/de/story/49953344.md
- es: https://zeli.app/es/story/49953344 · markdown: https://zeli.app/es/story/49953344.md
- ru: https://zeli.app/ru/story/49953344 · markdown: https://zeli.app/ru/story/49953344.md
