JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 28.0w AdaCore Inc
C and C++


PARSE.CSBICXX20 : Capturing Structured Bindings Requires C++20

Summary

A lambda captures a structured binding in a language mode earlier than C++20. Capturing structured bindings requires C++20.

Properties

Class Name Capturing Structured Bindings Requires C++20
Significance style
Mnemonic PARSE.CSBICXX20
Categories None
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. However, warning instances of this class that are issued as parser errors (rather than parser warnings) will be discarded when using factory configuration settings. To prevent these instances from being discarded, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Capturing Structured Bindings Requires C++20"
To disable checks for this warning class, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Capturing Structured Bindings Requires C++20"

Example

int f()
{
    int values[2] = {1, 2};
    auto [first, second] = values;
    auto get = [first]() { return first; }; // 'Capturing Structured Bindings Requires C++20' warning issued here
    return get() + second;
}

int sum_fixed()
{
    int values[2] = {1, 2};
    auto [first, second] = values;
    auto get = [saved = first]() { return saved; }; // ok: init-capture creates an ordinary captured variable in C++17
    return get() + second;
}

To reproduce this example, analyze it with the following configuration:

WARNING_FILTER += allow class="Capturing Structured Bindings Requires C++20"
# GNU 7 accepts structured binding captures as an extension before C++20.
COMPILER_MODELS += g++ -> gpp:64.70000.1.0
g++ -c -std=c++17 example.cpp

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

To report problems with this documentation, please visit https://support.adacore.com/csm.