[PATCH] Fixed error recovery if sizeof is used without parenthesis

Serge Pavlov sepavloff at gmail.com
Tue Jan 14 09:52:22 PST 2014


  Updated patch according to Richard Smith's comments.

http://llvm-reviews.chandlerc.com/D2440

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D2440?vs=6180&id=6448#toc

Files:
  include/clang/Parse/Parser.h
  lib/Parse/ParseExpr.cpp
  test/SemaCXX/expressions.cpp

Index: include/clang/Parse/Parser.h
===================================================================
--- include/clang/Parse/Parser.h
+++ include/clang/Parse/Parser.h
@@ -1788,6 +1788,7 @@
   /// disambiguation will occur.
   enum TentativeCXXTypeIdContext {
     TypeIdInParens,
+    TypeIdUnambiguous,
     TypeIdAsTemplateArgument
   };
 
@@ -1806,6 +1807,16 @@
     return isTypeIdInParens(isAmbiguous);
   }
 
+  /// \brief Checks if the current tokens form type-id or expression.
+  /// It is similar to isTypeIdInParens but does not suppose that type-id
+  /// is in parenthesis.
+  bool isTypeIdUnambiguously() {
+    bool IsAmbiguous;
+    if (getLangOpts().CPlusPlus)
+      return isCXXTypeId(TypeIdUnambiguous, IsAmbiguous);
+    return isTypeSpecifierQualifier();
+  }
+
   /// isCXXDeclarationStatement - C++-specialized function that disambiguates
   /// between a declaration or an expression statement, when parsing function
   /// bodies. Returns true for declaration, false for expression.
Index: lib/Parse/ParseExpr.cpp
===================================================================
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -1492,8 +1492,7 @@
     // pathenthesis around type name.
     if (OpTok.is(tok::kw_sizeof)  || OpTok.is(tok::kw___alignof) ||
         OpTok.is(tok::kw_alignof) || OpTok.is(tok::kw__Alignof)) {
-      bool isAmbiguousTypeId;
-      if (isTypeIdInParens(isAmbiguousTypeId)) {
+      if (isTypeIdUnambiguously()) {
         DeclSpec DS(AttrFactory);
         ParseSpecifierQualifierList(DS);
         Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
Index: test/SemaCXX/expressions.cpp
===================================================================
--- test/SemaCXX/expressions.cpp
+++ test/SemaCXX/expressions.cpp
@@ -118,3 +118,10 @@
   (void)s1.foo();
   (void)s2.foo();
 }
+
+namespace pr16992 {
+  typedef int T;
+  unsigned getsz() {
+    return (sizeof T());
+  }
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2440.2.patch
Type: text/x-patch
Size: 1959 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140114/f1fa7c52/attachment.bin>


More information about the cfe-commits mailing list