]> granicus.if.org Git - clang/commitdiff
Fix the end-location of a CXXTemporaryObjectExpr when it is created with a initialize...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 11 Sep 2013 23:23:27 +0000 (23:23 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 11 Sep 2013 23:23:27 +0000 (23:23 +0000)
rdar://14887351

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190561 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprCXX.cpp
test/Index/annotate-tokens-cxx0x.cpp

index 3da38f794f3d51a09607b0c45b886efefb4cc10b..55589e6d21f92d32146ad8fa6457a1b615a68046 100644 (file)
@@ -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,
index 49f7efb285a10288717d826c840c4962b193764b..4e6d156dfa9ff55b0bae8bf06ece3ae6acc5f62c 100644 (file)
@@ -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 _E>
+  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<int> 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