r/cpp • • 1d ago

Pattern Matching for C++29

https://mpark.github.io/programming/2026/11/30/pattern-matching-for-cpp29/
219 Upvotes

94 comments sorted by

View all comments

Show parent comment

1

u/Salty-Paint-9700 1d ago

3

u/mcypark 1d ago

Right, in this case since we have a concrete type pair<int, int>, we know [...] and _ both match it, and are able to warn. But that's true in general with other patterns as well, for example:

void f(int x) {
  match (x) {
    case int i => use(i);
    case _ => ; // redundant warning
  }
}

1

u/Salty-Paint-9700 1d ago

Shouldn't that be an error? I can't think of a case where this would be desirable.

3

u/mcypark 1d ago

It could easily be defined to be an error. I don't have a super clear, strong opinion on this one actually. The warning is mostly because I can't think of another place in the language that diagnoses unreachable code as an error.

1

u/Salty-Paint-9700 1d ago

Fair enough.