aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema
diff options
context:
space:
mode:
authorSebastian Redl <sebastian.redl@getdesigned.at>2012-01-23 22:09:39 +0000
committerSebastian Redl <sebastian.redl@getdesigned.at>2012-01-23 22:09:39 +0000
commitb832f6dea893f25b40500a04781286236281cb20 (patch)
tree4150adcc5c9abc204366eb0e52c74040cdb88952 /lib/Sema
parent05b7846d871fb0d3229e4b30fa5935bc858f3547 (diff)
Minor fixups for auto deduction of initializer lists.
Fix some review comments. Add a test for deduction when std::initializer_list isn't available yet. Fix redundant error messages. This fixes and outstanding FIXME too. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148735 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r--lib/Sema/SemaDecl.cpp3
-rw-r--r--lib/Sema/SemaDeclCXX.cpp11
-rw-r--r--lib/Sema/SemaExprCXX.cpp3
-rw-r--r--lib/Sema/SemaOverload.cpp2
-rw-r--r--lib/Sema/SemaStmt.cpp3
-rw-r--r--lib/Sema/SemaTemplateDeduction.cpp22
6 files changed, 24 insertions, 20 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 696e84234c..980c59c4c9 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -6011,7 +6011,8 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init,
// C++11 [decl.spec.auto]p6. Deduce the type which 'auto' stands in for.
if (TypeMayContainAuto && VDecl->getType()->getContainedAutoType()) {
TypeSourceInfo *DeducedType = 0;
- if (!DeduceAutoType(VDecl->getTypeSourceInfo(), Init, DeducedType))
+ if (DeduceAutoType(VDecl->getTypeSourceInfo(), Init, DeducedType) ==
+ DAR_Failed)
DiagnoseAutoDeductionFailure(VDecl, Init);
if (!DeducedType) {
RealDecl->setInvalidDecl();
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 983e815f60..b706cdc9fb 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -5809,12 +5809,13 @@ bool Sema::isStdInitializerList(QualType Ty, QualType *Element) {
CXXRecordDecl *TemplateClass = Template->getTemplatedDecl();
if (TemplateClass->getIdentifier() !=
&PP.getIdentifierTable().get("initializer_list") ||
- !TemplateClass->getDeclContext()->Equals(getStdNamespace()))
+ !getStdNamespace()->InEnclosingNamespaceSetOf(
+ TemplateClass->getDeclContext()))
return false;
// This is a template called std::initializer_list, but is it the right
// template?
TemplateParameterList *Params = Template->getTemplateParameters();
- if (Params->size() != 1)
+ if (Params->getMinRequiredArguments() != 1)
return false;
if (!isa<TemplateTypeParmDecl>(Params->getParam(0)))
return false;
@@ -5857,7 +5858,8 @@ static ClassTemplateDecl *LookupStdInitializerList(Sema &S, SourceLocation Loc){
// We found some template called std::initializer_list. Now verify that it's
// correct.
TemplateParameterList *Params = Template->getTemplateParameters();
- if (Params->size() != 1 || !isa<TemplateTypeParmDecl>(Params->getParam(0))) {
+ if (Params->getMinRequiredArguments() != 1 ||
+ !isa<TemplateTypeParmDecl>(Params->getParam(0))) {
S.Diag(Template->getLocation(), diag::err_malformed_std_initializer_list);
return 0;
}
@@ -9102,7 +9104,8 @@ void Sema::AddCXXDirectInitializerToDecl(Decl *RealDecl,
Expr *Init = Exprs.get()[0];
TypeSourceInfo *DeducedType = 0;
- if (!DeduceAutoType(VDecl->getTypeSourceInfo(), Init, DeducedType))
+ if (DeduceAutoType(VDecl->getTypeSourceInfo(), Init, DeducedType) ==
+ DAR_Failed)
DiagnoseAutoDeductionFailure(VDecl, Init);
if (!DeducedType) {
RealDecl->setInvalidDecl();
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index 3d155a5cf3..bea0954c6f 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -952,7 +952,8 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
<< AllocType << TypeRange);
}
TypeSourceInfo *DeducedType = 0;
- if (!DeduceAutoType(AllocTypeInfo, ConstructorArgs.get()[0], DeducedType))
+ if (DeduceAutoType(AllocTypeInfo, ConstructorArgs.get()[0], DeducedType) ==
+ DAR_Failed)
return ExprError(Diag(StartLoc, diag::err_auto_new_deduction_failure)
<< AllocType
<< ConstructorArgs.get()[0]->getType()
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index 931573bb29..fac3c26d0e 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -4111,7 +4111,7 @@ TryListConversion(Sema &S, InitListExpr *From, QualType ToType,
Result.setBad(BadConversionSequence::no_conversion, From, ToType);
Result.setListInitializationSequence();
- // We need a complete type for what follows. Incomplete types can bever be
+ // We need a complete type for what follows. Incomplete types can never be
// initialized from init lists.
if (S.RequireCompleteType(From->getLocStart(), ToType, S.PDiag()))
return Result;
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 2d843393a2..86bb74040a 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -1201,7 +1201,8 @@ static bool FinishForRangeVarDecl(Sema &SemaRef, VarDecl *Decl, Expr *Init,
// AddInitializerToDecl, so we can produce a more suitable diagnostic.
TypeSourceInfo *InitTSI = 0;
if ((!isa<InitListExpr>(Init) && Init->getType()->isVoidType()) ||
- !SemaRef.DeduceAutoType(Decl->getTypeSourceInfo(), Init, InitTSI))
+ SemaRef.DeduceAutoType(Decl->getTypeSourceInfo(), Init, InitTSI) ==
+ Sema::DAR_Failed)
SemaRef.Diag(Loc, diag) << Init->getType();
if (!InitTSI) {
Decl->setInvalidDecl();
diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp
index 0d74f24f4d..adc6994fb0 100644
--- a/lib/Sema/SemaTemplateDeduction.cpp
+++ b/lib/Sema/SemaTemplateDeduction.cpp
@@ -3376,20 +3376,18 @@ namespace {
/// dependent. This will be set to null if deduction succeeded, but auto
/// substitution failed; the appropriate diagnostic will already have been
/// produced in that case.
-///
-/// \returns true if deduction succeeded, false if it failed.
-bool
+Sema::DeduceAutoResult
Sema::DeduceAutoType(TypeSourceInfo *Type, Expr *&Init,
TypeSourceInfo *&Result) {
if (Init->getType()->isNonOverloadPlaceholderType()) {
ExprResult result = CheckPlaceholderExpr(Init);
- if (result.isInvalid()) return false;
+ if (result.isInvalid()) return DAR_FailedAlreadyDiagnosed;
Init = result.take();
}
if (Init->isTypeDependent()) {
Result = Type;
- return true;
+ return DAR_Succeeded;
}
SourceLocation Loc = Init->getExprLoc();
@@ -3418,7 +3416,7 @@ Sema::DeduceAutoType(TypeSourceInfo *Type, Expr *&Init,
if (AdjustFunctionParmAndArgTypesForDeduction(*this, &TemplateParams,
FuncParam, InitType, Init,
TDF))
- return false;
+ return DAR_Failed;
TemplateDeductionInfo Info(Context, Loc);
@@ -3428,22 +3426,22 @@ Sema::DeduceAutoType(TypeSourceInfo *Type, Expr *&Init,
if (DeduceTemplateArgumentsByTypeMatch(*this, &TemplateParams, FuncParam,
InitList->getInit(i)->getType(),
Info, Deduced, TDF))
- return false;
+ return DAR_Failed;
}
} else {
if (DeduceTemplateArgumentsByTypeMatch(*this, &TemplateParams, FuncParam,
InitType, Info, Deduced, TDF))
- return false;
+ return DAR_Failed;
}
QualType DeducedType = Deduced[0].getAsType();
if (DeducedType.isNull())
- return false;
+ return DAR_Failed;
if (InitList) {
DeducedType = BuildStdInitializerList(DeducedType, Loc);
if (DeducedType.isNull())
- return false;
+ return DAR_FailedAlreadyDiagnosed;
}
Result = SubstituteAutoTransform(*this, DeducedType).TransformType(Type);
@@ -3455,10 +3453,10 @@ Sema::DeduceAutoType(TypeSourceInfo *Type, Expr *&Init,
Sema::OriginalCallArg(FuncParam,0,InitType),
Result->getType())) {
Result = 0;
- return false;
+ return DAR_Failed;
}
- return true;
+ return DAR_Succeeded;
}
void Sema::DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init) {