[cfe-dev] Statement attributes and TemplateDependent = 1

Javier López via cfe-dev cfe-dev at lists.llvm.org
Fri Oct 20 04:26:38 PDT 2017


Hi,

I have defined a new attribute (whose subject is the null statement) in
Clang as follows

def MyAttr : StmtAttr {
  let Spellings = [CXX11<"", "my_attr", 201603>];
  let Args = [ExprArgument<"Cond">];
//  let Subjects = [NullStmt];
  let TemplateDependent = 1;
  let Documentation = [Undocumented];
}

Currently, it is correctly parsed and added to the AST.  In fact, the
intended behavior of that attribute also works -as long as it is part
of the body of a non-templated function-.

However, instantiation of the ExprArgument fails for a function
template even if TemplateDependent was set, e.g.

template<typename _T> void foo(_T a) {
  [[my_attr(a > 0)]];
}

generates this (AttributedStmt subtree only).  Please note the `_T'
instead of 'int':'int'.

| | | |-AttributedStmt 0xccb5cc0 <line:12:3, col:20>
| | | | |-MyAttr 0xccb5ca8 <col:5, col:17>
| | | | | `-BinaryOperator 0xccb5c70 <col:12, col:16> '<dependent
type>' '>'
| | | | |   |-DeclRefExpr 0xccb5a70 <col:12> '_T' lvalue ParmVar
0xccb56c0 'a' '_T'
| | | | |   `-IntegerLiteral 0xccb5a98 <col:16> 'int' 0
| | | | `-NullStmt 0xccb5c98 <col:20>

Additionally, I have noted that GNU-style attributes whose subject is a
Funtion -and that contain a ExprArgument-, e.g. `diagnose_if', are
correctly instantiated.

I would appreciate any help or suggestion on where to start looking.



More information about the cfe-dev mailing list