Fix PR9488: 'auto' type substitution can fail (for instance, if it creates a reference-to-void type). Don't crash if it does.
Also fix an issue where type source information for the resulting type was being lost.
llvm-svn: 127811
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a10b325..540c4e0 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -4664,15 +4664,17 @@
// 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.