]> granicus.if.org Git - clang/commitdiff
Fixed error recovery if sizeof is used without parenthesis
authorSerge Pavlov <sepavloff@gmail.com>
Wed, 15 Jan 2014 01:53:39 +0000 (01:53 +0000)
committerSerge Pavlov <sepavloff@gmail.com>
Wed, 15 Jan 2014 01:53:39 +0000 (01:53 +0000)
Changes made in r192200 fixed PR16992, which requested fixit suggesting
parenthesis if sizeof is followed by type-id. However expression in form
T() followed by ')' was incorrectly considered as a type-id if 'T' is
typedef name. This change fixes this case.

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

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

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

index 9d0d1b605903f1896192e749aa9950904be6ebec..aa7aca30af1d0627cfa0c5381cdc2efbdce6d39c 100644 (file)
@@ -1788,6 +1788,7 @@ private:
   /// disambiguation will occur.
   enum TentativeCXXTypeIdContext {
     TypeIdInParens,
+    TypeIdUnambiguous,
     TypeIdAsTemplateArgument
   };
 
@@ -1806,6 +1807,16 @@ private:
     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 d94155ba6c6e2bf11c7cc7fd6de1e5e5e3e15297..f7b0afe60d8866f7b5e5adfbfc0b3d078542e08f 100644 (file)
@@ -1492,8 +1492,7 @@ Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok,
     // 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 2635fb8d176a87199bc630720216cf3df58c23a8..25a9c841725c1c513dab64b24e1164fc214aafa7 100644 (file)
@@ -118,3 +118,10 @@ void test3() {
   (void)s1.foo();
   (void)s2.foo();
 }
+
+namespace pr16992 {
+  typedef int T;
+  unsigned getsz() {
+    return (sizeof T());
+  }
+}