]> granicus.if.org Git - clang/commitdiff
Eagerly correct typos in ParenExprs that may be type casts for non-C++ code.
authorKaelyn Takata <rikka@google.com>
Fri, 1 May 2015 19:36:25 +0000 (19:36 +0000)
committerKaelyn Takata <rikka@google.com>
Fri, 1 May 2015 19:36:25 +0000 (19:36 +0000)
This is needed to ensure the type casts are parsed properly. Fixes
PR23101.

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

lib/Parse/ParseExpr.cpp
test/Sema/typo-correction.c

index e889085b829e30b09afdc3f7092644c69629bc30..5116991c0f746c270917c96c7758922d8ce5de0c 100644 (file)
@@ -2285,6 +2285,11 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
     InMessageExpressionRAIIObject InMessage(*this, false);
 
     Result = ParseExpression(MaybeTypeCast);
+    if (!getLangOpts().CPlusPlus && MaybeTypeCast && Result.isUsable()) {
+      // Correct typos in non-C++ code earlier so that implicit-cast-like
+      // expressions are parsed correctly.
+      Result = Actions.CorrectDelayedTyposInExpr(Result);
+    }
     ExprType = SimpleExpr;
 
     if (isFoldOperator(Tok.getKind()) && NextToken().is(tok::ellipsis))
index be9a1f3e4829dc2c134f409b86a4cc4b8fd59276..d457257b3c3a517ed7a564582a2e21431ae91415 100644 (file)
@@ -34,3 +34,9 @@ int c11Generic(int arg) {
   _Generic(hello, int : banana)();  // expected-error-re {{use of undeclared identifier 'hello'{{$}}}}
   _Generic(arg, int : bandana)();  // expected-error {{use of undeclared identifier 'bandana'; did you mean 'banana'?}}
 }
+
+typedef long long __m128i __attribute__((__vector_size__(16)));
+int PR23101(__m128i __x) {
+  return foo((__v2di)__x);  // expected-warning {{implicit declaration of function 'foo'}} \
+                            // expected-error {{use of undeclared identifier '__v2di'}}
+}