[cfe-commits] r148735 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaOverload.cpp lib/Sema/SemaStmt.cpp lib/Sema/SemaTemplateDeduction.cpp test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp test/SemaObjCXX/properties.mm
Sebastian Redl
sebastian.redl at getdesigned.at
Mon Jan 23 14:09:39 PST 2012
Author: cornedbee
Date: Mon Jan 23 16:09:39 2012
New Revision: 148735
URL: http://llvm.org/viewvc/llvm-project?rev=148735&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
cfe/trunk/test/SemaObjCXX/properties.mm
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=148735&r1=148734&r2=148735&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Jan 23 16:09:39 2012
@@ -4644,8 +4644,15 @@
FunctionDecl *&Specialization,
sema::TemplateDeductionInfo &Info);
- bool DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer,
- TypeSourceInfo *&Result);
+ /// \brief Result type of DeduceAutoType.
+ enum DeduceAutoResult {
+ DAR_Succeeded,
+ DAR_Failed,
+ DAR_FailedAlreadyDiagnosed
+ };
+
+ DeduceAutoResult DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer,
+ TypeSourceInfo *&Result);
void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init);
FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1,
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=148735&r1=148734&r2=148735&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jan 23 16:09:39 2012
@@ -6011,7 +6011,8 @@
// 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();
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=148735&r1=148734&r2=148735&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Jan 23 16:09:39 2012
@@ -5809,12 +5809,13 @@
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 @@
// 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 @@
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();
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=148735&r1=148734&r2=148735&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Jan 23 16:09:39 2012
@@ -952,7 +952,8 @@
<< 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()
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=148735&r1=148734&r2=148735&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Mon Jan 23 16:09:39 2012
@@ -4111,7 +4111,7 @@
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;
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=148735&r1=148734&r2=148735&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Mon Jan 23 16:09:39 2012
@@ -1201,7 +1201,8 @@
// 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();
Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=148735&r1=148734&r2=148735&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Mon Jan 23 16:09:39 2012
@@ -3376,20 +3376,18 @@
/// 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 @@
if (AdjustFunctionParmAndArgTypesForDeduction(*this, &TemplateParams,
FuncParam, InitType, Init,
TDF))
- return false;
+ return DAR_Failed;
TemplateDeductionInfo Info(Context, Loc);
@@ -3428,22 +3426,22 @@
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::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) {
Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp?rev=148735&r1=148734&r2=148735&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp Mon Jan 23 16:09:39 2012
@@ -92,8 +92,7 @@
template<typename T> T g(T);
void f(X *x) {
- // FIXME: we should really only get the first diagnostic here.
- auto value = x->method; // expected-error {{reference to non-static member function must be called}} expected-error{{variable 'value' with type 'auto' has incompatible initializer of type '<bound member function type>'}}
+ auto value = x->method; // expected-error {{reference to non-static member function must be called}}
if (value) { }
auto funcptr = &g<int>;
@@ -101,4 +100,5 @@
}
}
-// TODO: if the initializer is a braced-init-list, deduce auto as std::initializer_list<T>.
+// if the initializer is a braced-init-list, deduce auto as std::initializer_list<T>:
+// see SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
Modified: cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp?rev=148735&r1=148734&r2=148735&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp Mon Jan 23 16:09:39 2012
@@ -1,5 +1,10 @@
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// This must obviously come before the definition of std::initializer_list.
+void missing_initializerlist() {
+ auto l = {1, 2, 3, 4}; // expected-error {{std::initializer_list was not found}}
+}
+
namespace std {
typedef decltype(sizeof(int)) size_t;
Modified: cfe/trunk/test/SemaObjCXX/properties.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/properties.mm?rev=148735&r1=148734&r2=148735&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/properties.mm (original)
+++ cfe/trunk/test/SemaObjCXX/properties.mm Mon Jan 23 16:09:39 2012
@@ -28,7 +28,7 @@
- (int) z;
@end
void test2(Test2 *a) {
- auto y = a.y; // expected-error {{expected getter method not found on object of type 'Test2 *'}} expected-error {{variable 'y' with type 'auto' has incompatible initializer of type}}
+ auto y = a.y; // expected-error {{expected getter method not found on object of type 'Test2 *'}}
auto z = a.z;
}
More information about the cfe-commits
mailing list