[cfe-commits] r73177 - in /cfe/trunk: lib/Parse/ParseExpr.cpp test/SemaCXX/typename-expression.cpp

Eli Friedman eli.friedman at gmail.com
Wed Jun 10 17:33:42 PDT 2009


Author: efriedma
Date: Wed Jun 10 19:33:41 2009
New Revision: 73177

URL: http://llvm.org/viewvc/llvm-project?rev=73177&view=rev
Log:
PR4364: fix parsing 'typename' in an expression.


Added:
    cfe/trunk/test/SemaCXX/typename-expression.cpp
Modified:
    cfe/trunk/lib/Parse/ParseExpr.cpp

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=73177&r1=73176&r2=73177&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Wed Jun 10 19:33:41 2009
@@ -749,7 +749,13 @@
       Diag(Tok, diag::err_expected_expression);
       return ExprError();
     }
-    
+
+    if (SavedKind == tok::kw_typename) {
+      // postfix-expression: typename-specifier '(' expression-list[opt] ')'
+      if (!TryAnnotateTypeOrScopeToken())
+        return ExprError();
+    }
+
     // postfix-expression: simple-type-specifier '(' expression-list[opt] ')'
     //
     DeclSpec DS;

Added: cfe/trunk/test/SemaCXX/typename-expression.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typename-expression.cpp?rev=73177&view=auto

==============================================================================
--- cfe/trunk/test/SemaCXX/typename-expression.cpp (added)
+++ cfe/trunk/test/SemaCXX/typename-expression.cpp Wed Jun 10 19:33:41 2009
@@ -0,0 +1,19 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+// PR4364
+template<class T> struct a {
+  T b() {
+    return typename T::x();
+  }
+};
+struct B {
+  typedef B x;
+};
+B c() {
+  a<B> x;
+  return x.b();
+}
+
+// Some extra tests for invalid cases
+template<class T> struct test2 { T b() { return typename T::a; } }; // expected-error{{expected '(' for function-style cast or type construction}}
+template<class T> struct test3 { T b() { return typename a; } }; // expected-error{{expected a qualified name after 'typename'}}





More information about the cfe-commits mailing list