<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58953>58953</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Destructuring assignment (structure binding) does not generate "unused variable" warning when one variable remains unused
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          alexandrustinov
      </td>
    </tr>
</table>

<pre>
    We need a function which returns structure Result with some value and error code, kind of Go language style error handling (see https://go.dev/doc/tutorial/handle-errors for reference).
The result need to be handled using destructuring assignment, C++17 feature (see https://en.cppreference.com/w/cpp/language/structured_binding)


Actual behavior: compiler does not generate warning if error code is not handled, it generates warning when both value and error variable are unused only, considering them as "single variable" [value, error], while those are supposed to be handled as separate variables.

Expected behavior: Compiler should generate warning when either value or error variable is unused. For our case the calling function must handle the result error code before processing the result value. If the error handling is omitted then compiler should notify about that.

    #include <stdio.h>

    struct Result {
        int value;
        int error;
    };

    Result func(int arg) {
        if (arg) {
            return {arg, 0};
        }
        else {
            return {0, -1}; // -1 means faulure here
        }
    }

    int main() {
        auto [value, error] = func(0); // simulating faulure

    //    if (!error) // we forgot to handle error code, compiler should generate warning about unused variable, but it does not
            printf("value = %d", value);

    }

    // clang++ --std=c++17 -Wunused-variable unused_destructure.cpp
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyFVU2T2jgQ_TXmosKF7fEABx9mIEntdWurckzJchtrIyTKkiDz7_dJ_oABkqXASK1W6_VT93Ntmo_qOzFN1DDOWq-Fk0azSydFx3pyvteWWdd7gSGxv8l65dhFuo5ZcyR25soT47ph1PemZ8I0lOQ79lPCZFr2zTDF9cHzAyHMh6LRr8MWJfWBJfnGErHOuZNNirck_4rvwaQNnTFojMDTeWd6yRWGcR8tYxDLWkTqqaWetMCx2zRZ7ZPV2z8dwRyRxsScYTUNR2LmbTi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