Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -17975,7 +17975,7 @@ // immediately. For all other classes, we mark their virtual members // at the end of the translation unit. if (Class->isLocalClass()) - MarkVirtualMembersReferenced(Loc, Class); + MarkVirtualMembersReferenced(Loc, Class->getDefinition()); else VTableUses.push_back(std::make_pair(Class, Loc)); } Index: clang/test/SemaCXX/warn-undefined-internal.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/warn-undefined-internal.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only -Wundefined-internal -verify %s + +void test1() { + struct S { virtual void f(); }; + // expected-warning@-1{{function 'test1()::S::f' has internal linkage but is not defined}} + S s; + // expected-note@-1{{used here}} +} + +void test2() { + struct S; + struct S { virtual void f(); }; + // expected-warning@-1{{function 'test2()::S::f' has internal linkage but is not defined}} + S s; + // expected-note@-1{{used here}} +}