Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -7074,6 +7074,7 @@ // single void argument. // We let through "const void" here because Sema::GetTypeForDeclarator // already checks for that case. + ParmVarDecl *Prev = nullptr; if (FTIHasNonVoidParameters(FTI) && FTI.Params[0].Param) { for (unsigned i = 0, e = FTI.NumParams; i != e; ++i) { ParmVarDecl *Param = cast(FTI.Params[i].Param); @@ -7081,8 +7082,17 @@ Param->setDeclContext(NewFD); Params.push_back(Param); - if (Param->isInvalidDecl()) + if (Param->isInvalidDecl()) { NewFD->setInvalidDecl(); + if (!Param->hasDefaultArg() && Prev && Prev->hasDefaultArg()) { + for (unsigned j = i; j != 0; --j) { + ParmVarDecl *Param = cast(FTI.Params[j - 1].Param); + if (!Param->hasDefaultArg()) break; + Param->setDefaultArg(nullptr); + } + } + } + Prev = Param; } } Index: test/SemaCXX/default1.cpp =================================================================== --- test/SemaCXX/default1.cpp +++ test/SemaCXX/default1.cpp @@ -62,3 +62,7 @@ j(2, 3); // expected-error{{too many arguments to function call, expected at most single argument 'f', have 2}} } } + +int pr20055_f(int x = 0, int y = UNDEFINED); // expected-error{{use of undeclared identifier}} \ + // expected-note{{candidate function not viable}} +int pr20055_v = pr20055_f(0); // expected-error{{no matching function for call}}