From: Saleem Abdulrasool Date: Wed, 15 Oct 2014 21:37:55 +0000 (+0000) Subject: Sema: handle AttributedTypeLocs in C++14 auto deduction X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=715b1b7df87d4da02c120bbd360910b9da0e609b;p=clang Sema: handle AttributedTypeLocs in C++14 auto deduction When performing a type deduction from the return type, the FunctionDecl may be attributed with a calling convention. In such a case, the retrieved type location may be an AttributedTypeLoc. Performing a castAs on such a type loc would result in an assertion as they are not derived types. Ensure that we correctly handle the attributed type location by looking through it to the modified type loc. Fixes an assertion triggered in C++14 mode. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219851 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 464206eafe..c03ac86de0 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -2755,8 +2755,11 @@ bool Sema::DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD, SourceLocation ReturnLoc, Expr *&RetExpr, AutoType *AT) { - TypeLoc OrigResultType = FD->getTypeSourceInfo()->getTypeLoc(). - IgnoreParens().castAs().getReturnLoc(); + TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc(); + if (auto ATL = TL.getAs()) + TL = ATL.getModifiedLoc(); + TypeLoc OrigResultType = + TL.IgnoreParens().castAs().getReturnLoc(); QualType Deduced; if (RetExpr && isa(RetExpr)) { diff --git a/test/Sema/attributed-auto-deduction.cpp b/test/Sema/attributed-auto-deduction.cpp new file mode 100644 index 0000000000..d8dc43d669 --- /dev/null +++ b/test/Sema/attributed-auto-deduction.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple armv7 -std=c++14 -x c++ %s -fsyntax-only +// expected-no-diagnostics + +void deduce() { + auto lambda = [](int i) __attribute__ (( pcs("aapcs") )) { + return i; + }; + lambda(42); +} +