[cfe-dev] Type source info for function template instances.
Enea Zaffanella
zaffanella at cs.unipr.it
Sun Mar 7 11:29:28 PST 2010
John McCall wrote:
> On Mar 5, 2010, at 12:23 PM, Enea Zaffanella wrote:
[...]
>> The patch passes all but a single test:
>>
>> Failing Tests (1):
>> Clang :: SemaTemplate/instantiate-expr-2.cpp
>>
>> An assertion is failing:
>>
>> clang: Sema.h:3416: clang::Decl* clang::Sema::LocalInstantiationScope::getInstantiationOf(const clang::Decl*): Assertion `Result && "declaration was not instantiated in this scope!"' failed.
>>
>> The relevant code in the example is the following:
>> ================
>> template<typename T, unsigned long N> struct IntegralConstant { };
>>
>> template<typename T>
>> struct X0 {
>> void f(T x, IntegralConstant<T, sizeof(x)>);
>> };
>>
>> void test_X0(X0<int> x, IntegralConstant<int, sizeof(int)> ic) {
>> x.f(5,ic);
>> }
>> ================
>>
>> The assertion crash disappears if you replace sizeof(x) with sizeof(T) in the declaration of method X0<T>::f.
>>
>> Could this be an already existing, but hidden bug that was uncovered by our patch?
>
> Hmm, yes. Test case which crashes on ToT (doesn't work in gcc at all, which doesn't do parameter scopes properly):
>
> template <class T> class Foo {
> void (*ptr)(T x, char (&array)[sizeof(x)]);
> };
> template class Foo<int>;
>
> We need to override TreeTransform::TransformFunctionProtoType in TemplateInstantiator; it can just call your new method.
>
> John.
>
I think we managed to do what was required.
We override TransformFunctionProtoType as suggested: we have moved here
most of the code from our helper function SubstFunctionTypeSourceInfo,
so that the latter has been simplified.
We had a few tests that were failing because, due to overriding, we were
ending up substituting parameter declarations using a Sema object having
no active instantiation scope at all. Hence, we added a few calls to
LocalInstantiationScope Scope(*this, CurrentInstantiationScope != 0);
where needed (please double check them).
The revised patch was computed against r97917 and passes all tests, here
included the one you were proposing here above.
Cheers,
Enea Zaffanella.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Subst-Function-TInfo-3.patch
Type: text/x-patch
Size: 14951 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100307/8c03789d/attachment.bin>
More information about the cfe-dev
mailing list