]> granicus.if.org Git - clang/commitdiff
Try typo correction on all initialization arguments and be less
authorKaelyn Takata <rikka@google.com>
Tue, 16 Dec 2014 23:07:00 +0000 (23:07 +0000)
committerKaelyn Takata <rikka@google.com>
Tue, 16 Dec 2014 23:07:00 +0000 (23:07 +0000)
pessimistic about when to do so.

This also fixes PR21905 as the initialization argument was no longer
viewed as being type dependent due to the TypoExpr being type-cast.

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

lib/Sema/SemaDecl.cpp
test/SemaCXX/typo-correction-delayed.cpp

index 298e4e705f653c6b76614143a9eca00084dcd260..d4b87ba615e01738915c7eb015db84e59e839682 100644 (file)
@@ -8806,12 +8806,10 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init,
       Args = MultiExprArg(CXXDirectInit->getExprs(),
                           CXXDirectInit->getNumExprs());
 
-    // Try to correct any TypoExprs if there might be some in the initialization
-    // arguments (TypoExprs are marked as type-dependent).
-    // TODO: Handle typo correction when there's more than one argument?
-    if (Args.size() == 1 && Expr::hasAnyTypeDependentArguments(Args)) {
+    // Try to correct any TypoExprs in the initialization arguments.
+    for (size_t Idx = 0; Idx < Args.size(); ++Idx) {
       ExprResult Res =
-          CorrectDelayedTyposInExpr(Args[0], [this, Entity, Kind](Expr *E) {
+          CorrectDelayedTyposInExpr(Args[Idx], [this, Entity, Kind](Expr *E) {
             InitializationSequence Init(*this, Entity, Kind, MultiExprArg(E));
             return Init.Failed() ? ExprError() : E;
           });
@@ -8819,8 +8817,8 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init,
         VDecl->setInvalidDecl();
         return;
       }
-      if (Res.get() != Args[0])
-        Args[0] = Res.get();
+      if (Res.get() != Args[Idx])
+        Args[Idx] = Res.get();
     }
 
     InitializationSequence InitSeq(*this, Entity, Kind, Args);
index c91fb6ca65e3b35abc46d579ba9df7d7c1c2446d..a9bc91e0308d3d248fa838609a3e93cd22fb5f1a 100644 (file)
@@ -143,3 +143,7 @@ void test() {
   int x = variableX.getX();
 }
 }
+
+namespace PR21905 {
+int (*a) () = (void)Z;  // expected-error-re {{use of undeclared identifier 'Z'{{$}}}}
+}