Skip to content

A2-10-1: False positive around null identifiers on tuple-like types in structural binding (relevant C++17 only) #581

Open
@knewbury01

Description

@knewbury01

Affected rules

  • A2-10-1
  • RULE-5-3
  • M0-1-3

Description

the extractor creates local variables for each identifier, and one for the entire binding. The later is of type tuple without a name, so it gets (null) .
This means if you have another structured binding later on, the rule is falsely triggered because the name is the same.

Example

#include <tuple>
void f9(int x, int y){
  auto tup = std::make_tuple(1, 2);
  const auto & [ a, b ] = tup;
  const auto & [ c, d ] = tup;
}

this example will require additional stubbing to be added to the tuple.h stub, as it currently will not compile due to tuples in that stub not currently having elements. Compilation error message: error: type 'const std::tuple<int, int>' decomposes into 0 elements, but 2 names were provided (ie needs to have mechanism to have elements and get those elements)

another example is the current finding in openpilot- dmonitoring.cc:82:10 from query IdentifierHiding.ql

Metadata

Metadata

Assignees

No one assigned

    Labels

    C++17Difficulty-LowA false positive or false negative report which is expected to take <1 day effort to addressImpact-LowStandard-AUTOSARfalse positive/false negativeAn issue related to observed false positives or false negatives.wontfixThis will not be worked on

    Type

    No type

    Projects

    Status

    Triaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions