diff options
author | Bill Wendling <isanbard@gmail.com> | 2011-03-21 21:32:22 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2011-03-21 21:32:22 +0000 |
commit | 2d1a83ae5cb93607cc6530cd302205af7a0c5211 (patch) | |
tree | 510caf19234ec73a90dc3875866bd44a9ad05353 | |
parent | 005273673eabe8988b4a23872c4c1c136224618b (diff) | |
download | llvm-2d1a83ae5cb93607cc6530cd302205af7a0c5211.zip llvm-2d1a83ae5cb93607cc6530cd302205af7a0c5211.tar.gz llvm-2d1a83ae5cb93607cc6530cd302205af7a0c5211.tar.bz2 |
--- Merging r127811 into '.':
A test/SemaCXX/auto-subst-failure.cpp
U include/clang/Sema/Sema.h
U lib/Sema/SemaDeclCXX.cpp
U lib/Sema/SemaExprCXX.cpp
U lib/Sema/SemaDecl.cpp
U lib/Sema/SemaTemplateDeduction.cpp
--- Merging r127971 into '.':
U tools/libclang/CIndex.cpp
llvm-svn: 128026
-rw-r--r-- | clang/include/clang/Sema/Sema.h | 3 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 10 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplateDeduction.cpp | 11 | ||||
-rw-r--r-- | clang/test/SemaCXX/auto-subst-failure.cpp | 15 | ||||
-rw-r--r-- | clang/tools/libclang/CIndex.cpp | 14 |
7 files changed, 49 insertions, 20 deletions
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 70ec778..ec4007b 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -3856,7 +3856,8 @@ public: FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info); - bool DeduceAutoType(QualType AutoType, Expr *Initializer, QualType &Result); + bool DeduceAutoType(TypeSourceInfo *AutoType, Expr *Initializer, + TypeSourceInfo *&Result); FunctionTemplateDecl *getMoreSpecializedTemplate(FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 89b2185..065149b 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -4640,15 +4640,17 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, // C++0x [decl.spec.auto]p6. Deduce the type which 'auto' stands in for. if (TypeMayContainAuto && VDecl->getType()->getContainedAutoType()) { - QualType DeducedType; - if (!DeduceAutoType(VDecl->getType(), Init, DeducedType)) { + TypeSourceInfo *DeducedType = 0; + if (!DeduceAutoType(VDecl->getTypeSourceInfo(), Init, DeducedType)) Diag(VDecl->getLocation(), diag::err_auto_var_deduction_failure) << VDecl->getDeclName() << VDecl->getType() << Init->getType() << Init->getSourceRange(); + if (!DeducedType) { RealDecl->setInvalidDecl(); return; } - VDecl->setType(DeducedType); + VDecl->setTypeSourceInfo(DeducedType); + VDecl->setType(DeducedType->getType()); // If this is a redeclaration, check that the type we just deduced matches // the previously declared type. diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 6eae9ba..141d1ff 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -6046,15 +6046,17 @@ void Sema::AddCXXDirectInitializerToDecl(Decl *RealDecl, } Expr *Init = Exprs.get()[0]; - QualType DeducedType; - if (!DeduceAutoType(VDecl->getType(), Init, DeducedType)) { + TypeSourceInfo *DeducedType = 0; + if (!DeduceAutoType(VDecl->getTypeSourceInfo(), Init, DeducedType)) Diag(VDecl->getLocation(), diag::err_auto_var_deduction_failure) << VDecl->getDeclName() << VDecl->getType() << Init->getType() << Init->getSourceRange(); + if (!DeducedType) { RealDecl->setInvalidDecl(); return; } - VDecl->setType(DeducedType); + VDecl->setTypeSourceInfo(DeducedType); + VDecl->setType(DeducedType->getType()); // If this is a redeclaration, check that the type we just deduced matches // the previously declared type. diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index d68613e..884011e 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -848,16 +848,18 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, diag::err_auto_new_ctor_multiple_expressions) << AllocType << TypeRange); } - QualType DeducedType; - if (!DeduceAutoType(AllocType, ConstructorArgs.get()[0], DeducedType)) + TypeSourceInfo *DeducedType = 0; + if (!DeduceAutoType(AllocTypeInfo, ConstructorArgs.get()[0], DeducedType)) return ExprError(Diag(StartLoc, diag::err_auto_new_deduction_failure) << AllocType << ConstructorArgs.get()[0]->getType() << TypeRange << ConstructorArgs.get()[0]->getSourceRange()); + if (!DeducedType) + return ExprError(); - AllocType = DeducedType; - AllocTypeInfo = Context.getTrivialTypeSourceInfo(AllocType, StartLoc); + AllocTypeInfo = DeducedType; + AllocType = AllocTypeInfo->getType(); } // Per C++0x [expr.new]p5, the type being constructed may be a diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index c6b4d96..202a736 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -3003,11 +3003,14 @@ namespace { /// /// \param Result if type deduction was successful, this will be set to the /// deduced type. This may still contain undeduced autos if the type is -/// dependent. +/// 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::DeduceAutoType(QualType Type, Expr *Init, QualType &Result) { +Sema::DeduceAutoType(TypeSourceInfo *Type, Expr *Init, + TypeSourceInfo *&Result) { if (Init->isTypeDependent()) { Result = Type; return true; @@ -3025,8 +3028,10 @@ Sema::DeduceAutoType(QualType Type, Expr *Init, QualType &Result) { FixedSizeTemplateParameterList<1> TemplateParams(Loc, Loc, &TemplParamPtr, Loc); - QualType FuncParam = + TypeSourceInfo *FuncParamInfo = SubstituteAutoTransform(*this, TemplArg).TransformType(Type); + assert(FuncParamInfo && "substituting template parameter for 'auto' failed"); + QualType FuncParam = FuncParamInfo->getType(); // Deduce type of TemplParam in Func(Init) llvm::SmallVector<DeducedTemplateArgument, 1> Deduced; diff --git a/clang/test/SemaCXX/auto-subst-failure.cpp b/clang/test/SemaCXX/auto-subst-failure.cpp new file mode 100644 index 0000000..442c7e8 --- /dev/null +++ b/clang/test/SemaCXX/auto-subst-failure.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x + +void f() { + auto a = f(); // expected-error {{variable has incomplete type 'void'}} + auto &b = f(); // expected-error {{cannot form a reference to 'void'}} + auto *c = f(); // expected-error {{incompatible initializer of type 'void'}} + + auto d(f()); // expected-error {{variable has incomplete type 'void'}} + auto &&e(f()); // expected-error {{cannot form a reference to 'void'}} + auto *g(f()); // expected-error {{incompatible initializer of type 'void'}} + + (void)new auto(f()); // expected-error {{allocation of incomplete type 'void'}} + (void)new auto&(f()); // expected-error {{cannot form a reference to 'void'}} + (void)new auto*(f()); // expected-error {{incompatible constructor argument of type 'void'}} +} diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 74f9079..2f3ef45 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -2382,12 +2382,6 @@ static void clang_parseTranslationUnit_Impl(void *UserData) { } llvm::SmallVector<const char *, 16> Args; - - // The 'source_filename' argument is optional. If the caller does not - // specify it then it is assumed that the source file is specified - // in the actual argument list. - if (source_filename) - Args.push_back(source_filename); // Since the Clang C library is primarily used by batch tools dealing with // (often very broken) source code, where spell-checking can have a @@ -2408,6 +2402,14 @@ static void clang_parseTranslationUnit_Impl(void *UserData) { Args.insert(Args.end(), command_line_args, command_line_args + num_command_line_args); + // The 'source_filename' argument is optional. If the caller does not + // specify it then it is assumed that the source file is specified + // in the actual argument list. + // Put the source file after command_line_args otherwise if '-x' flag is + // present it will be unused. + if (source_filename) + Args.push_back(source_filename); + // Do we need the detailed preprocessing record? if (options & CXTranslationUnit_DetailedPreprocessingRecord) { Args.push_back("-Xclang"); |