--- description: "Learn more about: Warning C26448 USE_GSL_FINALLY" title: Warning C26448 ms.date: 03/22/2018 f1_keywords: ["C26448", "USE_GSL_FINALLY"] helpviewer_keywords: ["C26448"] --- # Warning C26448 > Consider using `gsl::finally` if final action is intended (gsl.util) C++ Core Guidelines: [GSL.util: Utilities](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#SS-utilities) The Guidelines Support Library provides a convenient utility to implement the *final action* concept. Since the C++ language doesn't support **try-finally** constructs, it became common to implement custom cleanup types that would invoke arbitrary actions on destruction. The `gsl::finally` utility is implemented in this way and provides a more uniform way to perform final actions across a code base. There are also cases where final actions are performed in an old-fashioned C-style way by using **`goto`** statements (which is discouraged by [C26438 NO_GOTO](c26438.md)). It's hard to detect the exact intention in code that heavily uses **`goto`**, but some heuristics can help to find better candidates for cleanup. ## Remarks - This rule is lightweight and uses label names to guess about opportunities to use final action objects. - Label names that can raise a warning contain words like "end", "final", "clean", and so on. - Warnings appear at the **`goto`** statements. You may see verbose output on some occasions, but the output may help in prioritizing code, depending on its complexity. - This rule always goes in pair with [C26438 NO_GOTO](c26438.md). Depending on the priorities, one of these rules can be disabled. Code analysis name: `USE_GSL_FINALLY` ## Example Cleanup with multiple goto statements: ```cpp void poll(connection_info info) { connection c = {}; if (!c.open(info)) return; while (c.wait()) { connection::header h{}; connection::signature s{}; if (!c.read_header(h)) goto end; // C26448 and C26438 if (!c.read_signature(s)) goto end; // C26448 and C26438 // ... } end: c.close(); } ``` Cleanup with multiple goto statements replaced by `gsl::finally`: ```cpp void poll(connection_info info) { connection c = {}; if (!c.open(info)) return; auto end = gsl::finally([&c] { c.close(); }); while (c.wait()) { connection::header h{}; connection::signature s{}; if (!c.read_header(h)) return; if (!c.read_signature(s)) return; // ... } } ```