[cfe-dev] Visiting implicit copy assignment

Kim Gräsman kim.grasman at gmail.com
Mon Apr 20 21:08:20 PDT 2015


Hi Reid,

On Mon, Apr 20, 2015 at 11:00 PM, Reid Kleckner <rnk at google.com> wrote:
> On Fri, Apr 17, 2015 at 12:58 PM, Kim Gräsman <kim.grasman at gmail.com> wrote:
>>
>> I've noticed that MSVC always exports the copy assignment operator if
>> the class is marked __declspec(dllexport), so I'm trying to mimic that
>> behavior.
>
> Clang already implements that behavior if you use __declspec(dllexport). :-)
> But I assume you have your reasons for wanting to use .def files.

Right, yes. The FOO_EXPORT macros have always bugged me, so I wanted
to see if there was a way to generate the export tables out-of-line
for portable code bases.

>> Is there a documented way to handle this? It seems Clang only defines
>> these methods if they are used, but for tooling it would be useful to
>> be able to work with them whether they're actually defined or not.
>
> See where Clang implements this in SemaDeclCXX.cpp. It calls
> Sema::ForceDeclarationOfImplicitMembers(), and then iterates over them and
> marks them referenced to ensure they are emitted.

Thanks, that looks straightforward enough!

I guess my next question is tooling-related -- how do I best get a
hold of Sema and call
ForceDeclarationOfImplicitMembers/MarkFunctionReferenced before
traversing the AST (either with a visitor or preferably AST matchers)?
It seems dangerous to modify the AST (which I assume this does) as
part of traversal, and I haven't found a way to run matchers on a
Decl.

I managed to smuggle Sema into a tool by passing a SourceFileCallbacks
implementation to stash the CompilerInstance into newFrontEndFactory,
but it felt decidedly dirty :-)

Thanks,
- Kim




More information about the cfe-dev mailing list