[cfe-dev] Problem with a change on newFrontendActionFactory

David Blaikie dblaikie at gmail.com
Thu May 1 13:21:01 PDT 2014


On Thu, May 1, 2014 at 1:19 PM, Nico Weber <thakis at chromium.org> wrote:
> On Thu, May 1, 2014 at 1:17 PM, David Blaikie <dblaikie at gmail.com> wrote:
>> On Thu, May 1, 2014 at 1:12 PM, Richard Smith <richard at metafoo.co.uk> wrote:
>>> On Thu, May 1, 2014 at 12:55 PM, Etienne Ollivier <eollivier at bsu.edu> wrote:
>>>>
>>>> Hello,
>>>> I updated my clang repository recently and I an error appeared that was
>>>> not
>>>> there before:
>>>>
>>>> error: no viable conversion from 'std::unique_ptr<FrontendActionFactory>'
>>>> to
>>>>       'clang::tooling::ToolAction *'
>>>>         return Tool.run(newFrontendActionFactory<MyPluginASTAction>());
>>>>                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>
>>>> It is because newFrontendActionFactory has been changed to work with
>>>> std::unique_ptr. So if I change my code to
>>>>    return Tool.run(&(*newFrontendActionFactory<MyPluginASTAction>()));
>>>
>>>
>>> You can use .get() rather than the slightly non-obvious &*.
>>>
>>>>
>>>> it works. The only little problem is that it can be confusing for users
>>>> since is not the way it is written in the documentation, like on this
>>>> pages:
>>>> http://clang.llvm.org/docs/LibTooling.html
>>>> http://clang.llvm.org/docs/LibASTMatchersTutorial.html
>>>
>>>
>>> Thanks, I've updated the documentation.
>>
>> I'm trying to understand how the ownership used to work/is meant to work now...
>
> The result of newFrontendActionFactory() used to be leaked. Now it's
> freed at the end-of-statement cleanup of the returned (invisible)
> unique_ptr temporary.

Ah, I was starting to reach that conclusion.

So 'run' isn't meant to take ownership? (seems fair, since it doesn't
need to copy the pointer/save it beyond the life of the function)

Where possible I've been trying to transform such APIs (that take a
non-owning pointer to an object) to take a reference, that way they
work seamlessly with unique_ptr or raw pointers (in both cases you
just dereference the thing and pass it to the other thing). JUst a
thought, not a request for action, etc.

- David



More information about the cfe-dev mailing list