@@ -15654,6 +15654,46 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc,
15654
15654
15655
15655
switch (Opc) {
15656
15656
case BO_Assign:
15657
+ // ROOT hack: we want to support constructs like n = new TNamed() and if n
15658
+ // wasn't declared we should declare it.
15659
+ if (DeclRefExpr* DRE = dyn_cast<DeclRefExpr>(LHSExpr)) {
15660
+ if (VarDecl* VD = dyn_cast<VarDecl>(DRE->getDecl())) {
15661
+ if (const AutoType* aTy = dyn_cast<AutoType>(VD->getType().getTypePtr())) {
15662
+ if (const AnnotateAttr* A = VD->getAttr<AnnotateAttr>()) {
15663
+ // If the deduction didn't take place and it is our special
15664
+ // annotation
15665
+ if (!aTy->isDeduced() && A->getAnnotation().equals("__Auto")) {
15666
+ QualType ResTy;
15667
+ ASTContext& C = getASTContext();
15668
+ TypeSourceInfo* TrivialTSI
15669
+ = C.getTrivialTypeSourceInfo(VD->getType());
15670
+ TemplateDeductionInfo Info(RHSExpr->getExprLoc());
15671
+ TemplateDeductionResult Result =
15672
+ DeduceAutoType(TrivialTSI->getTypeLoc(), RHSExpr, ResTy, Info);
15673
+ if (Result != TDK_Success && Result != TDK_AlreadyDiagnosed) {
15674
+ Diag(VD->getLocation(), diag::err_auto_var_requires_init)
15675
+ << VD->getDeclName() << VD->getType();
15676
+ VD->setInvalidDecl();
15677
+
15678
+ return ExprError();
15679
+ }
15680
+ if (!ResTy.isNull()) {
15681
+ VD->setTypeSourceInfo(C.getTrivialTypeSourceInfo(ResTy));
15682
+ VD->setType(ResTy);
15683
+ }
15684
+ VD->setInit(DefaultLvalueConversion(RHSExpr).get());
15685
+ PushOnScopeChains(VD, getCurScope(), /*Add to ctx*/true);
15686
+
15687
+ // Here we need to return 'something' to make the parser happy.
15688
+ // A reference to the decl is semantically closest to what we want.
15689
+ return BuildDeclRefExpr(VD, VD->getType(), VK_LValue,
15690
+ SourceLocation());
15691
+ }
15692
+ }
15693
+ }
15694
+ }
15695
+ }
15696
+
15657
15697
ResultTy = CheckAssignmentOperands(LHS.get(), RHS, OpLoc, QualType(), Opc);
15658
15698
if (getLangOpts().CPlusPlus &&
15659
15699
LHS.get()->getObjectKind() != OK_ObjCProperty) {
0 commit comments