Skip to content

Patternia v0.6.2 Release Note

Release Date: December 23, 2025 Version: 0.6.2


Overview

Patternia v0.6.2 introduces enhanced compile-time safety through the addition of [[nodiscard]] attribute to the match_builder class. This release prevents incomplete or unused match expressions from silently producing undefined behavior or logical errors, providing developers with clear compiler warnings when match expressions are not properly terminated.


API Changes

[[nodiscard]] Attribute for match_builder

Added: The match_builder class is now marked with the [[nodiscard]] attribute to prevent unused match expressions.

// v0.6.2 - [[nodiscard]] with custom warning message
template <typename TV, bool HasMatchFallback, typename... Cases>
class [[nodiscard(
    "[Patternia.match]: incomplete match expression. "
    "Call .otherwise(...) or .end() to finalize.")]]
match_builder {
    // Implementation...
};

Example:

// Incomplete match expression - generates compiler warning
match(value)
    .when(lit(1) >> "one")
    .when(lit(2) >> "two");
// WARNING: [Patternia.match]: incomplete match expression. Call .otherwise(...) or .end() to finalize.

// Correct usage - properly terminated
auto result = match(value)
    .when(lit(1) >> "one")
    .when(lit(2) >> "two")
    .otherwise([]() { return "other"; });

Key Benefits: - Compile-Time Safety: Detects unused match expressions at compile time - Clear Diagnostics: Custom warning message provides actionable guidance - Prevents Bugs: Avoids silent failures from incomplete pattern matches


Implementation Details

Custom Warning Message

The [[nodiscard]] attribute includes a custom warning message to guide developers:

class [[nodiscard(
    "[Patternia.match]: incomplete match expression. "
    "Call .otherwise(...) or .end() to finalize.")]]
match_builder {
    // Class implementation...
};

Code Cleanup in otherwise() Method

Refactored: Removed duplicate static_assert statement in the otherwise() method for cleaner code.


Migration Guide

From v0.6.1 to v0.6.2

Impact: Minimal - this change only introduces compiler warnings, not breaking changes.

1. Address New Warnings:

// v0.6.1 - No warning
void old_code(int value) {
    match(value)
        .when(lit(1) >> []() { do_something(); })
        .otherwise([]() { do_other(); });
}

// v0.6.2 - Warning generated
void new_code(int value) {
    auto result = match(value)
        .when(lit(1) >> []() { do_something(); return 1; })
        .otherwise([]() { do_other(); return 0; });
}

2. Intentional Side-Effect Operations:

For side-effect only operations, use explicit (void) cast:

void logging(int level) {
    (void)match(level)
        .when(lit(LOG_INFO) >> []() { log_info(); })
        .otherwise([]() { log_warning(); });
    // Explicit cast indicates intentional disregard
}

Breaking Changes

None. This release is fully backward compatible. The [[nodiscard]] attribute only generates compiler warnings and does not change the behavior of existing code.


Performance Impact

Runtime Performance: No impact - [[nodiscard]] is a compile-time attribute only Compilation Time: No impact - attribute processing is negligible Binary Size: No impact - no runtime code generated


Note: This release focuses on enhancing compile-time safety and developer experience. The core pattern matching functionality and runtime behavior remain unchanged from v0.6.1.