Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -16595,7 +16595,8 @@ bool AddToScope = true; NamedDecl *ND = ActOnFunctionDeclarator(DCScope, D, DC, TInfo, Previous, TemplateParams, AddToScope); - if (!ND) return nullptr; + if (!ND || ND->isInvalidDecl()) + return nullptr; assert(ND->getLexicalDeclContext() == CurContext); Index: clang/test/CodeGenCXX/invalid-decl.cpp =================================================================== --- /dev/null +++ clang/test/CodeGenCXX/invalid-decl.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -emit-llvm %s -verify +class test1 { + template friend int bar(bool = true) { // expected-note {{previous declaration is here}} + return 1; + } + template friend int bar(bool); // expected-error {{friend declaration specifying a default argument must be the only declaration}} +}; + +class test2 { + friend int bar(bool = true) // expected-note {{previous declaration is here}} + { + return 1; + } + friend int bar(bool); // expected-error {{friend declaration specifying a default argument must be the only declaration}} +};