// directly pointed to, and expanding embedded structures. Note that
// these rules are sufficient to prevent recursive encoding of the
// same type.
- getObjCEncodingForTypeImpl(T, S, true, true, Field);
+ getObjCEncodingForTypeImpl(T, S, true, true, Field,
+ true /* outermost type */);
}
void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S,
bool ExpandPointedToStructures,
bool ExpandStructures,
- FieldDecl *FD) const {
+ FieldDecl *FD,
+ bool OutermostType) const {
if (const BuiltinType *BT = T->getAsBuiltinType()) {
if (FD && FD->isBitField()) {
const Expr *E = FD->getBitWidth();
}
else if (const PointerType *PT = T->getAsPointerType()) {
QualType PointeeTy = PT->getPointeeType();
+ if (OutermostType && PointeeTy.isConstQualified())
+ S += 'r';
if (isObjCIdType(PointeeTy)) {
S += '@';
return;
getObjCEncodingForTypeImpl(Field->getType(), S, false, true,
(*Field));
} else {
+ // FIXME! Another legacy kludge: 32-bit longs are encoded as
+ // 'l' or 'L', but not always. For typedefs, we need to use
+ // 'i' or 'I' instead if encoding a struct field, or a pointer!
getObjCEncodingForTypeImpl(Field->getType(), S, false, true,
FD);
}
// RUN: grep -e "\^{Innermost=CC}" %t | count 1 &&
// RUN: grep -e "{Derived=#ib32b8b3b8sb16b8b8b2b8ccb6}" %t | count 1 &&
// RUN: grep -e "{B1=#@c}" %t | count 1 &&
-// RUN: grep -e "v12@0:4\[3\[4{Test=i}]]8" %t | count 1
+// RUN: grep -e "v12@0:4\[3\[4{Test=i}]]8" %t | count 1 &&
+// RUN: grep -e "r^{S=i}" %t | count 1
@class Int1;
-(void) test3: (Test [3] [4])b {}
@end
+struct S { int iS; };
int main()
{
const char *en = @encode(Derived);
const char *eb = @encode(B1);
+ const char *es = @encode(const struct S *);
+ const char *ec = @encode(const struct S);
}