r225389 - Handle OpaqueValueExprs more intelligently in the TransformTypos tree

Kaelyn Takata rikka at google.com
Wed Jan 7 13:16:39 PST 2015


Author: rikka
Date: Wed Jan  7 15:16:39 2015
New Revision: 225389

URL: http://llvm.org/viewvc/llvm-project?rev=225389&view=rev
Log:
Handle OpaqueValueExprs more intelligently in the TransformTypos tree
transform.

Also diagnose typos in the initializer of an invalid C++ declaration.
Both issues were hit using the same line of test code, depending on
whether the code was treated as C or C++.

Fixes PR22092.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/Sema/typo-correction.c
    cfe/trunk/test/SemaCXX/typo-correction-delayed.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=225389&r1=225388&r2=225389&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Jan  7 15:16:39 2015
@@ -8574,8 +8574,10 @@ void Sema::AddInitializerToDecl(Decl *Re
                                 bool DirectInit, bool TypeMayContainAuto) {
   // If there is no declaration, there was an error parsing it.  Just ignore
   // the initializer.
-  if (!RealDecl || RealDecl->isInvalidDecl())
+  if (!RealDecl || RealDecl->isInvalidDecl()) {
+    CorrectDelayedTyposInExpr(Init);
     return;
+  }
 
   if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(RealDecl)) {
     // With declarators parsed the way they are, the parser cannot

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=225389&r1=225388&r2=225389&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Jan  7 15:16:39 2015
@@ -6141,6 +6141,12 @@ public:
 
   ExprResult TransformLambdaExpr(LambdaExpr *E) { return Owned(E); }
 
+  ExprResult TransformOpaqueValueExpr(OpaqueValueExpr *E) {
+    if (Expr *SE = E->getSourceExpr())
+      return TransformExpr(SE);
+    return BaseTransform::TransformOpaqueValueExpr(E);
+  }
+
   ExprResult Transform(Expr *E) {
     ExprResult Res;
     while (true) {

Modified: cfe/trunk/test/Sema/typo-correction.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/typo-correction.c?rev=225389&r1=225388&r2=225389&view=diff
==============================================================================
--- cfe/trunk/test/Sema/typo-correction.c (original)
+++ cfe/trunk/test/Sema/typo-correction.c Wed Jan  7 15:16:39 2015
@@ -9,3 +9,6 @@ void PR21656() {
   float x;
   x = (float)arst;  // expected-error-re {{use of undeclared identifier 'arst'{{$}}}}
 }
+
+a = b ? : 0;  // expected-warning {{type specifier missing, defaults to 'int'}} \
+              // expected-error {{use of undeclared identifier 'b'}}

Modified: cfe/trunk/test/SemaCXX/typo-correction-delayed.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction-delayed.cpp?rev=225389&r1=225388&r2=225389&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/typo-correction-delayed.cpp (original)
+++ cfe/trunk/test/SemaCXX/typo-correction-delayed.cpp Wed Jan  7 15:16:39 2015
@@ -152,3 +152,8 @@ namespace PR21947 {
 int blue;  // expected-note {{'blue' declared here}}
 __typeof blur y;  // expected-error {{use of undeclared identifier 'blur'; did you mean 'blue'?}}
 }
+
+namespace PR22092 {
+a = b ? : 0;  // expected-error {{C++ requires a type specifier for all declarations}} \
+              // expected-error-re {{use of undeclared identifier 'b'{{$}}}}
+}





More information about the cfe-commits mailing list