Bug 549130 - [C++17] Codan Checkers for Mistakes in Structured Bindings
Summary: [C++17] Codan Checkers for Mistakes in Structured Bindings
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-codan (show other bugs)
Version: Next   Edit
Hardware: PC All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: CDT Codan Inbox CLA
QA Contact: Elena Laskavaia CLA
URL:
Whiteboard:
Keywords:
Depends on: 522200
Blocks:
  Show dependency tree
 
Reported: 2019-07-10 07:07 EDT by Thomas Corbat CLA
Modified: 2019-07-10 07:07 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Corbat CLA 2019-07-10 07:07:06 EDT
The implementation of structured bindings accepts a superset of correct applications according to the C++ standard. This behavior is a deliberate design decision as we can provide better analysis and quickfixes through Codan in the problematic cases.

Checkers could be implemented for:
* Too many member variables in a decomposed type. The semantics currently need to have at least as many non-static members available to initialize each name.
* Accessibility of the members need to be public. Example test case by Nathan Ridge:
  // Class with private fields
  class Point {
  private:
    int x;
    int y;

    void foo() {
      // OK, a member function can destructure a Point.
      auto [x, y] = *this;
    }

    friend void bar(Point p) {
      // OK, a friend function can destructure a Point.
      auto [x, y] = p;
    }
  };

  void baz(Point p) {
    // Error, a non-member non-friend function cannot
    // destructure a Point.
    auto [x, y] = p;
  }

* All members need to be declared in the same class or base class
* The value member of tuple_size needs to be static