[cfe-commits] r92930 - in /cfe/trunk: lib/Parse/ParseExpr.cpp test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp
John McCall
rjmccall at apple.com
Thu Jan 7 11:29:58 PST 2010
Author: rjmccall
Date: Thu Jan 7 13:29:58 2010
New Revision: 92930
URL: http://llvm.org/viewvc/llvm-project?rev=92930&view=rev
Log:
When parsing an identifier as an expression in C++, only try to annotate it
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.
Modified:
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=92930&r1=92929&r2=92930&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Thu Jan 7 13:29:58 2010
@@ -616,9 +616,17 @@
// 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
Modified: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp?rev=92930&r1=92929&r2=92930&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p4.cpp Thu Jan 7 13:29:58 2010
@@ -166,7 +166,8 @@
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 @@
}
void test7() {
- Opaque0 _ = hiding; // expected-error {{expected '(' for function-style cast or type construction}}
+ Opaque0 _ = hiding; // expected-error {{does not refer to a value}}
}
};
More information about the cfe-commits
mailing list