]> granicus.if.org Git - clang/commitdiff
When parsing an identifier as an expression in C++, only try to annotate it
authorJohn McCall <rjmccall@apple.com>
Thu, 7 Jan 2010 19:29:58 +0000 (19:29 +0000)
committerJohn McCall <rjmccall@apple.com>
Thu, 7 Jan 2010 19:29:58 +0000 (19:29 +0000)
as a type or scope token if the next token requires it.

This eliminates a lot of redundant lookups in C++, but there's room for
improvement;  a better solution would do a single lookup whose kind and
results would be passed through the parser.

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

lib/Parse/ParseExpr.cpp
test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp

index bdbc67f782dcfd09c99984c1f037e3d4c028f6fc..4d6988d5f2cc6b49dc9cd2542e528d815e83db4b 100644 (file)
@@ -616,9 +616,17 @@ Parser::OwningExprResult Parser::ParseCastExpression(bool isUnaryExpression,
     // Turn a potentially qualified name into a annot_typename or
     // annot_cxxscope if it would be valid.  This handles things like x::y, etc.
     if (getLang().CPlusPlus) {
-      // If TryAnnotateTypeOrScopeToken annotates the token, tail recurse.
-      if (TryAnnotateTypeOrScopeToken())
-        return ParseCastExpression(isUnaryExpression, isAddressOfOperand);
+      // Avoid the unnecessary parse-time lookup in the common case
+      // where the syntax forbids a type.
+      const Token &Next = NextToken();
+      if (Next.is(tok::coloncolon) ||
+          (!ColonIsSacred && Next.is(tok::colon)) ||
+          Next.is(tok::less) ||
+          Next.is(tok::l_paren)) {
+        // If TryAnnotateTypeOrScopeToken annotates the token, tail recurse.
+        if (TryAnnotateTypeOrScopeToken())
+          return ParseCastExpression(isUnaryExpression, isAddressOfOperand);
+      }
     }
 
     // Consume the identifier so that we can see if it is followed by a '(' or
index f2dc64b80742c714556934980b24877cb711c65d..23da98ce7ee6dae87420f71c337e5595a828f4f5 100644 (file)
@@ -166,7 +166,8 @@ namespace test3 {
 
   template <class T> struct C : A<T> {
     using typename A<T>::type;
-    using typename A<T>::hiding; // expected-error {{'typename' keyword used on a non-type}}
+    using typename A<T>::hiding; // expected-note {{declared at}} \
+                                 // expected-error {{'typename' keyword used on a non-type}}
     using typename A<T>::union_member; // expected-error {{'typename' keyword used on a non-type}}
     using typename A<T>::enumerator; // expected-error {{'typename' keyword used on a non-type}}
 
@@ -175,7 +176,7 @@ namespace test3 {
     }
 
     void test7() {
-      Opaque0 _ = hiding; // expected-error {{expected '(' for function-style cast or type construction}}
+      Opaque0 _ = hiding; // expected-error {{does not refer to a value}}
     }
   };