]> granicus.if.org Git - clang/commitdiff
Fix the source range of CXXNewExprs. Fixes http://llvm.org/pr8661.
authorNico Weber <nicolasweber@gmx.de>
Mon, 22 Nov 2010 10:30:56 +0000 (10:30 +0000)
committerNico Weber <nicolasweber@gmx.de>
Mon, 22 Nov 2010 10:30:56 +0000 (10:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119966 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseDecl.cpp
lib/Parse/ParseExpr.cpp
lib/Parse/ParseExprCXX.cpp
lib/Sema/SemaType.cpp
test/SemaCXX/sourceranges.cpp [new file with mode: 0644]

index 121289696db8f69aef17dcfd3bb500a69dab6223..36054a9958afa4239742cd9f4d23ec2eb674f157 100644 (file)
@@ -1020,7 +1020,8 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
         ConsumeToken(); // The C++ scope.
         if (Tok.getAnnotationValue()) {
           ParsedType T = getTypeAnnotation(Tok);
-          isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, 
+          isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename,
+                                         Tok.getAnnotationEndLoc(), 
                                          PrevSpec, DiagID, T);
         }
         else
@@ -1082,7 +1083,8 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
     case tok::annot_typename: {
       if (Tok.getAnnotationValue()) {
         ParsedType T = getTypeAnnotation(Tok);
-        isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec,
+        isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename,
+                                       Tok.getAnnotationEndLoc(), PrevSpec,
                                        DiagID, T);
       } else
         DS.SetTypeSpecError();
@@ -1545,7 +1547,8 @@ bool Parser::ParseOptionalTypeSpecifier(DeclSpec &DS, bool& isInvalid,
   // simple-type-specifier:
   case tok::annot_typename: {
     if (ParsedType T = getTypeAnnotation(Tok)) {
-      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec,
+      isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename,
+                                     Tok.getAnnotationEndLoc(), PrevSpec,
                                      DiagID, T);
     } else
       DS.SetTypeSpecError();
index c4d09f2816f4d581a09601a2c07334355243bdbd..0accc4bcd8b0563231f51bc359f31d77757f66b0 100644 (file)
@@ -822,8 +822,8 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
 
       const char *PrevSpec = 0;
       unsigned DiagID;
-      DS.SetTypeSpecType(TST_typename, Tok.getLocation(), PrevSpec, DiagID, 
-                         Type);
+      DS.SetTypeSpecType(TST_typename, Tok.getAnnotationEndLoc(),
+                         PrevSpec, DiagID, Type);
       
       Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
       TypeResult Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
index 1d09fe2a1afbe0a06e69210b1725a883901ece63..24a1274b01a85d160cbe5fdb77b9d731271782ea 100644 (file)
@@ -912,8 +912,8 @@ void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) {
 
   // type-name
   case tok::annot_typename: {
-    DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, DiagID,
-                       getTypeAnnotation(Tok));
+    DS.SetTypeSpecType(DeclSpec::TST_typename, Tok.getAnnotationEndLoc(),
+                       PrevSpec, DiagID, getTypeAnnotation(Tok));
     
     DS.SetRangeEnd(Tok.getAnnotationEndLoc());
     ConsumeToken();
index fe0916e78708dfb21954ee28b24900ce74bf7b69..e1ee91843d979d71b9badaf532f8a84f2eabacc8 100644 (file)
@@ -1558,7 +1558,7 @@ namespace {
     void VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
       ElaboratedTypeKeyword Keyword
         = TypeWithKeyword::getKeywordForTypeSpec(DS.getTypeSpecType());
-      if (Keyword == ETK_Typename) {
+      if (DS.getTypeSpecType() == TST_typename) {
         TypeSourceInfo *TInfo = 0;
         Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo);
         if (TInfo) {
@@ -1576,7 +1576,7 @@ namespace {
     void VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
       ElaboratedTypeKeyword Keyword
         = TypeWithKeyword::getKeywordForTypeSpec(DS.getTypeSpecType());
-      if (Keyword == ETK_Typename) {
+      if (DS.getTypeSpecType() == TST_typename) {
         TypeSourceInfo *TInfo = 0;
         Sema::GetTypeFromParser(DS.getRepAsType(), &TInfo);
         if (TInfo) {
diff --git a/test/SemaCXX/sourceranges.cpp b/test/SemaCXX/sourceranges.cpp
new file mode 100644 (file)
index 0000000..c3ce279
--- /dev/null
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -ast-dump %s | FileCheck %s
+
+template<class T>
+class P {
+ public:
+  P(T* t) {}
+};
+
+namespace foo {
+class A {};
+enum B {};
+typedef int C;
+}
+
+int main() {
+  // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} <col:19, col:28> 'foo::class A *'
+  P<foo::A> p14 = new foo::A;
+  // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} <col:19, col:28> 'foo::enum B *'
+  P<foo::B> p24 = new foo::B;
+  // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} <col:19, col:28> 'foo::C *'
+  P<foo::C> pr4 = new foo::C;
+}