[cfe-commits] r57337 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/DeclBase.h include/clang/Parse/Action.h lib/AST/Decl.cpp lib/AST/DeclBase.cpp lib/Parse/ParseExpr.cpp lib/Sema/Sema.h lib/Sema/SemaExpr.cpp
Argiris Kirtzidis
akyrtzi at gmail.com
Fri Oct 10 13:34:49 PDT 2008
Steve Naroff wrote:
> + // Variable will be bound by-copy, make it const within the closure.
> + VD->getType().addConst();
> + return new BlockDeclRefExpr(VD, VD->getType(), Loc, false);
"VD->getType().addConst()" will add 'const' to a temporary QualType
returned by VD->getType(), it doesn't have any effect, e.g.:
void f() {
void (^blck)(void);
int v;
struct S {} s;
blck = ^{ int x; x = v+s; }; // reports "error: invalid operands to
binary expression ('int' and 'struct S')", 'const' is not added
}
it should probably be changed like this:
return new BlockDeclRefExpr(VD,
VD->getType()->getWithAdditionalQualifiers(QualType::Const), Loc, false);
BTW, how about adding methods like this to QualType class:
QualType withConst() { return getWithAdditionalQualifiers(Const); }
So that the above line becomes
return new BlockDeclRefExpr(VD, VD->getType().withConst(), Loc, false);
-Argiris
More information about the cfe-commits
mailing list