Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect insight to const auto& #13

Closed
rudalert opened this issue May 23, 2018 · 1 comment
Closed

Incorrect insight to const auto& #13

rudalert opened this issue May 23, 2018 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@rudalert
Copy link

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&&.

@andreasfertig andreasfertig added the bug Something isn't working label May 23, 2018
@andreasfertig andreasfertig self-assigned this May 23, 2018
andreasfertig pushed a commit that referenced this issue May 23, 2018
Due to lambdas there is special handling for QualType in case it is a
RecordDecl or a ClassTemplateSpecializationDecl. It appears that, if the
type is a ReferenceType the CV qualifiers come from the reference type
getPointeeTypeAsWritten(). Ohterwise they are empty. This fix adds
special handling for that, nearly the same way as TypePrinter.cpp does
it.
andreasfertig pushed a commit that referenced this issue May 23, 2018
Fixed #13: const disappeared in case of auto.
@andreasfertig
Copy link
Owner

Hello rudalert,

thanks for pointing this out. Totally correct, I dropped a const, as well as a possible volatile, here. There are a couple more places where this could occur. I pushed a fix for it, you can check it online.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants