Skip to content

Incorrect insight to const auto& #13

@rudalert

Description

@rudalert

The following example

#include <iostream>
#include <memory>

std::shared_ptr<int> create() {
    return std::make_shared<int>(42);
}

int main()
{
  const auto& car = create(); // 'const' disappeared!
  //However, the following does not compile:
  //std::shared_ptr<int> & ar = create();
  //error: non-const lvalue reference to type 'shared_ptr<...>' cannot bind to a temporary of type 'shared_ptr<...>'
  
  //must be:
  const std::shared_ptr<int> & car2 = create();
}

is translated incorrectly:

#include <iostream>
#include <memory>

std::shared_ptr<int> create() {
    return std::make_shared<int>(42);
}

int main()
{
  std::shared_ptr<int> & car = create(); // 'const' disappeared!
  //However, the following does not compile:
  //std::shared_ptr<int> & ar = create();
  //error: non-const lvalue reference to type 'shared_ptr<...>' cannot bind to a temporary of type 'shared_ptr<...>'
  
  //must be:
  const std::shared_ptr<int> & car2 = create();
}

Similar happens with const auto&&.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions