[cfe-commits] r147023 - in /cfe/trunk: lib/Sema/SemaExpr.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/PCH/chain-cxx.cpp test/SemaTemplate/instantiate-declref-ice.cpp

Richard Smith richard at metafoo.co.uk
Mon Jan 2 14:53:27 PST 2012


On Mon, January 2, 2012 21:37, Enea Zaffanella wrote:
> Il 21/12/2011 01:25, Richard Smith ha scritto:
>> Author: rsmith
>> Date: Tue Dec 20 18:25:33 2011
>> New Revision: 147023
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=147023&view=rev
>> Log:
>> C++ constant expression handling: eagerly instantiate static const integral
>> data members of class templates so that their values can be used in ICEs.
>> This
>> required reverting r105465, to get such instantiated members to be included
>> in serialized ASTs.
>
> Hi Richard.
>
> I noticed only now that your commit was reverting r105465:
>
>> --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp	2010/06/04 08:34:32
>> 105464
>> +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp	2010/06/04 09:35:39
>> 105465
>> @@ -373,7 +373,8 @@
>> SemaRef.CheckVariableDeclaration(Var, Previous, Redeclaration);
>>
>>
>> if (D->isOutOfLine()) { -    D->getLexicalDeclContext()->addDecl(Var);
>> +    if (!D->isStaticDataMember())
>> +      D->getLexicalDeclContext()->addDecl(Var);
>> Owner->makeDeclVisibleInContext(Var);
>> } else {
>> Owner->addDecl(Var);
>>
>
>
> For reference, the change in r105465 was discussed on the cfe-dev list
> in this thread:
>
> http://lists.cs.uiuc.edu/pipermail/cfe-dev/2010-June/009231.html

Firstly, no tests were introduced by r105465, and none broke when I reverted
it; do you have a case where this matters? (Is this important for some
external tool using libclang, perhaps?)

> where it was agreed that "Implicit instantiations should not show up in the
> translation unit context."

Well, they don't, necessarily -- they show up in the declaration context where
the data member template was defined. That doesn't seem obviously wrong to me,
but maybe it is. I asked Doug about this on IRC before making the change, and
he had no immediate objections.

> I understand from what you wrote above that these implicit
> instantiations need to occur in the serialized AST. Have you considered the
> possibility of replacing the (inline) static member declaration inside the
> implicit instantiation of the class template? This is basically what is done
> when instantiating out-of-line definitions of class methods, they appear to be
> "inline" (but not in the formal sense) method definition.

Right, in the case of a function template, we add a definition to an
already-instantiated declaration, which (for a member function) lives inside
the class template. It would be strange to mark an in-class declaration of a
static data member as being a definition, though, since definitions of static
data members can't appear within a class.

- Richard




More information about the cfe-commits mailing list