/// actual default expression is the subexpression.
llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
+ /// \brief The location where the default argument expression was used.
+ SourceLocation Loc;
+
protected:
- CXXDefaultArgExpr(StmtClass SC, ParmVarDecl *param)
+ CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
: Expr(SC,
param->hasUnparsedDefaultArg()
? param->getType().getNonReferenceType()
: param->getDefaultArg()->getType()),
- Param(param, false) { }
+ Param(param, false), Loc(Loc) { }
- CXXDefaultArgExpr(StmtClass SC, ParmVarDecl *param, Expr *SubExpr)
- : Expr(SC, SubExpr->getType()), Param(param, true)
+ CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
+ Expr *SubExpr)
+ : Expr(SC, SubExpr->getType()), Param(param, true), Loc(Loc)
{
*reinterpret_cast<Expr **>(this + 1) = SubExpr;
}
public:
// Param is the parameter whose default argument is used by this
// expression.
- static CXXDefaultArgExpr *Create(ASTContext &C, ParmVarDecl *Param) {
- return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Param);
+ static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
+ ParmVarDecl *Param) {
+ return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
}
// Param is the parameter whose default argument is used by this
// expression, and SubExpr is the expression that will actually be used.
- static CXXDefaultArgExpr *Create(ASTContext &C, ParmVarDecl *Param,
+ static CXXDefaultArgExpr *Create(ASTContext &C,
+ SourceLocation Loc,
+ ParmVarDecl *Param,
Expr *SubExpr);
// Retrieve the parameter that the argument was created from.
return getParam()->getDefaultArg();
}
+ /// \brief Retrieve the location where this default argument was actually
+ /// used.
+ SourceLocation getUsedLocation() const { return Loc; }
+
virtual SourceRange getSourceRange() const {
// Default argument expressions have no representation in the
// source, so they have an empty source range.
}
CXXDefaultArgExpr *
-CXXDefaultArgExpr::Create(ASTContext &C, ParmVarDecl *Param, Expr *SubExpr) {
+CXXDefaultArgExpr::Create(ASTContext &C, SourceLocation Loc,
+ ParmVarDecl *Param, Expr *SubExpr) {
void *Mem = C.Allocate(sizeof(CXXDefaultArgExpr) + sizeof(Stmt *));
- return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Param, SubExpr);
+ return new (Mem) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param,
+ SubExpr);
}
void CXXDefaultArgExpr::DoDestroy(ASTContext &C) {
return ExprError();
// Build the default argument expression.
- return Owned(CXXDefaultArgExpr::Create(Context, Param,
+ return Owned(CXXDefaultArgExpr::Create(Context, CallLoc, Param,
Result.takeAs<Expr>()));
}
}
// We already type-checked the argument, so we know it works.
- return Owned(CXXDefaultArgExpr::Create(Context, Param));
+ return Owned(CXXDefaultArgExpr::Create(Context, CallLoc, Param));
}
/// ConvertArgumentsForCall - Converts the arguments specified in
assert(!cast<FunctionDecl>(E->getParam()->getDeclContext())->
getDescribedFunctionTemplate() &&
"Default arg expressions are never formed in dependent cases.");
- return SemaRef.Owned(E->Retain());
+ return SemaRef.BuildCXXDefaultArgExpr(E->getUsedLocation(),
+ cast<FunctionDecl>(E->getParam()->getDeclContext()),
+ E->getParam());
}
/// By default, builds a new default-argument expression, which does not
/// require any semantic analysis. Subclasses may override this routine to
/// provide different behavior.
- OwningExprResult RebuildCXXDefaultArgExpr(ParmVarDecl *Param) {
- return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Param));
+ OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
+ ParmVarDecl *Param) {
+ return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
+ Param));
}
/// \brief Build a new C++ zero-initialization expression.
Param == E->getParam())
return SemaRef.Owned(E->Retain());
- return getDerived().RebuildCXXDefaultArgExpr(Param);
+ return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
}
template<typename Derived>
namespace PR5810 {
template<typename T>
struct allocator {
- allocator() { int a[sizeof(T) ? -1 : -1]; } // expected-error{{array size is negative}}
+ allocator() { int a[sizeof(T) ? -1 : -1]; } // expected-error2 {{array size is negative}}
};
template<typename T>
struct vector {
- vector(const allocator<T>& = allocator<T>()) {} // expected-note{{instantiation of}}
+ vector(const allocator<T>& = allocator<T>()) {} // expected-note2 {{instantiation of}}
};
struct A { };
-
+ struct B { };
+
template<typename>
void FilterVTs() {
vector<A> Result;
void f() {
vector<A> Result;
}
+
+ template<typename T>
+ struct X {
+ vector<B> bs;
+ X() { }
+ };
+
+ void f2() {
+ X<float> x; // expected-note{{member function}}
+ }
}