From e825cf3ff84c3d47c73ddd39fb66617567093981 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Wed, 11 Sep 2013 23:23:27 +0000 Subject: [PATCH] Fix the end-location of a CXXTemporaryObjectExpr when it is created with a initializer_list. rdar://14887351 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190561 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ExprCXX.cpp | 5 +++- test/Index/annotate-tokens-cxx0x.cpp | 44 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index 3da38f794f..55589e6d21 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -823,7 +823,10 @@ SourceLocation CXXTemporaryObjectExpr::getLocStart() const { } SourceLocation CXXTemporaryObjectExpr::getLocEnd() const { - return getParenOrBraceRange().getEnd(); + SourceLocation Loc = getParenOrBraceRange().getEnd(); + if (Loc.isInvalid() && getNumArgs()) + Loc = getArg(getNumArgs()-1)->getLocEnd(); + return Loc; } CXXConstructExpr *CXXConstructExpr::Create(const ASTContext &C, QualType T, diff --git a/test/Index/annotate-tokens-cxx0x.cpp b/test/Index/annotate-tokens-cxx0x.cpp index 49f7efb285..4e6d156dfa 100644 --- a/test/Index/annotate-tokens-cxx0x.cpp +++ b/test/Index/annotate-tokens-cxx0x.cpp @@ -23,6 +23,47 @@ class S : public B { virtual void foo(Int) override; }; +// Need std::initializer_list +namespace std { + typedef decltype(sizeof(int)) size_t; + + // libc++'s implementation + template + class initializer_list + { + const _E* __begin_; + size_t __size_; + + initializer_list(const _E* __b, size_t __s) + : __begin_(__b), + __size_(__s) + {} + + public: + typedef _E value_type; + typedef const _E& reference; + typedef const _E& const_reference; + typedef size_t size_type; + + typedef const _E* iterator; + typedef const _E* const_iterator; + + initializer_list() : __begin_(nullptr), __size_(0) {} + + size_t size() const {return __size_;} + const _E* begin() const {return __begin_;} + const _E* end() const {return __begin_ + __size_;} + }; +} + +struct Foo { + Foo(std::initializer_list il); +}; + +void test2() { + Foo{10}; +} + // RUN: c-index-test -test-annotate-tokens=%s:1:1:5:1 -fno-delayed-template-parsing -std=c++11 %s | FileCheck %s // CHECK: Identifier: "args" [3:20 - 3:24] SizeOfPackExpr=args:2:15 @@ -52,3 +93,6 @@ class S : public B { // CHECK-WITH-OVERRIDE: Punctuation: ")" [23:23 - 23:24] ParmDecl=:23:23 (Definition) // CHECK-WITH-OVERRIDE: Keyword: "override" [23:25 - 23:33] attribute(override)= // CHECK-WITH-OVERRIDE: Punctuation: ";" [23:33 - 23:34] ClassDecl=S:22:7 (Definition) + +// RUN: c-index-test -test-annotate-tokens=%s:64:1:65:1 -std=c++11 %s | FileCheck -check-prefix=CHECK-INITLIST %s +// CHECK-INITLIST: Identifier: "Foo" [64:3 - 64:6] TypeRef=struct Foo:59:8 -- 2.40.0