Bug 575134 - lambda with auto argument as an argument to a function results in "Invalid argument"
Summary: lambda with auto argument as an argument to a function results in "Invalid ar...
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 10.3.1   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-07-30 07:55 EDT by Kamil Mierzejewski CLA
Modified: 2021-07-30 07:55 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kamil Mierzejewski CLA 2021-07-30 07:55:21 EDT
The parser is unable to properly resolve function call, to a function which takes a function pointer as argument, with a lambda expression as argument when, the lambda has argument of auto type and its return type depends on argument type:


struct Obj {
	bool bmem;
};

class ObjPtr
{
public:
	const Obj* operator->() const { return &m_data; }
    Obj m_data;
};


Obj* func(bool(*predicate)(const ObjPtr&)  = {})
{
	return 0;
}

int main() {
    return func([](const auto& arg)
            {
                return arg->bmem;
            });

The call to "func" in main gets underlined as 'Invalid argument'. It only happens if the "func" argument type has overloaded operator-> and the result type of lambda is inferred from a "->" dereference of argument.

If I use ObjPtr instead of auto, it works correctly:

int main() {
    return func([](const ObjPtr& arg)
            {
                return arg->bmem;
            });
}