[cfe-dev] Remove explicit template specializations
Douglas Gregor
dgregor at apple.com
Wed Mar 2 14:14:20 PST 2011
On Mar 2, 2011, at 10:35 AM, Vassil Vassilev wrote:
> On 02.3.2011 г. 21:08, Douglas Gregor wrote:
>> On Mar 2, 2011, at 10:03 AM, Vassil Vassilev wrote:
>>
>>> Hi,
>>> Yes, but in my case I know that nothing depends on the specific specialization (I inject one artificially, analyze the output, get what I need and I want to remove it).
>> Injecting a specialization can cause a cascade of instantiations, some of which can refer back to that specialization. For example, you could end up instantiating a static data member of some other class template specialization that refers to a member of the specialization you injected.
>>
> I agree, but as I said nothing depends on the injected templated class and its explicit specialization in my case.
Then you have defined what goes into that class template in a *very* narrow way, that doesn't permit it to trigger any other instantiations that might capture or reproduce the specialization. That basically means that it doesn't interact with any of the other code in the translation unit that you don't control, e.g., it doesn't call a function that might be a function template.
>>> If I try to remove it like with DeclContext I end up with assert. It is not possible to remove it simply from the Scope (like I do with the when I create implicit function for the failed sema lookups (Sema::ImplicitlyDefineFunction()))
>> The Clang AST does not offer removal of nodes because it is extremely complicated to undo the effects of the addition of a node.
>>
> Yes I agree that dependency analysis upon c++ semantic tree is far away from trivial. However, there is one thing that I don't get isn't there clang::DeclContext::removeDecl(clang::Decl), which is public interface that removes decls from given DeclContext? I think you use it for shadow declarations in one place... (I am writing by hard but: Shadow->getDeclContext()->removeDecl(Shadow))
Frankly, I'd rather that DeclContext::removeDecl() go away. It's meant to support a very narrow use case with using declarations, and Sema handle things correctly, but it's really messy.
> I am curious do you plan to implement removing arbitrary nodes from the AST at some point?
We have no plans to do implement this.
- Doug
More information about the cfe-dev
mailing list