[cfe-dev] Type source info for function template instances.
Enea Zaffanella
zaffanella at cs.unipr.it
Fri Mar 5 12:23:15 PST 2010
John McCall wrote:
> Can you not "reattach" default argument expressions during
> TemplateDeclInstantiator::SubstFunctionType()? Or even better,
> transform them appropriately in TreeTransform. I would be much more
> comfortable doing either of these than suppressing diagnostics
> assumed to be redundant.
>
> John.
>
Hello John.
Please find attached a revised patch.
In this version, we no longer visit parameters twice,
so we no longer need to suppress diagnostics.
We (re-)discovered that we are NOT allowed to substitute the default
argument expressions when instantiating the function decl, because this
could eagerly generate diagnostics that should only be produced if and
when the default argument is actually used.
We added a new helper named
SubstFunctionTypeSourceInfo
which mimics the behavior of the existing
SubstFunctionType
but produces a TypeSourceInfo instead of a QualType.
We factored the common code that checks parameters in
CheckInstantiatedParams.
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?
Cheers,
Enea Zaffanella.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Subst-Function-TInfo-2.patch
Type: text/x-patch
Size: 8637 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100305/18a9d505/attachment.bin>
More information about the cfe-dev
mailing list