[cfe-dev] Template specialization: why drop attributes?
Sharlet, Dillon
dillon.sharlet at intel.com
Fri Jun 15 12:00:22 PDT 2012
Hello,
I am working on a custom attribute for an experimental project. I've just finally tracked down a problem where explicit template specializations have their attributes removed by Clang. I'm suspicious of the following function:
/// \brief Strips various properties off an implicit instantiation
/// that has just been explicitly specialized.
static void StripImplicitInstantiation(NamedDecl *D) {
// FIXME: "make check" is clean if the call to dropAttrs() is commented out.
D->dropAttrs();
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
FD->setInlineSpecified(false);
}
}
'dropAttrs' does exactly what you would expect: it removes the attributes from my explicit specialization. To me, this seems like incorrect behavior. Consider the following program:
template < int N >
int Test(int x) __attribute__((custom))
{
return x * N;
}
template < >
int Test < 1 > (int x) __attribute__((custom))
{
return x;
}
When I debug a call to Test < 1 >, it behaves as if the program was written like so:
template < int N >
int Test(int x) __attribute__((custom))
{
return x * N;
}
template < >
int Test < 1 > (int x) // custom attribute removed by StripImplicitInstantiation.
{
return x;
}
I was hoping to understand the reasoning for this before I commented out dropAttrs here. The comment above dropAttrs seems to imply that it might not be fully correct. What is "make check"?
Thank you for any insight into this issue!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120615/aba77d00/attachment.html>
More information about the cfe-dev
mailing list