Author: Stephan Bergmann Date: 2023-03-02T15:50:12+01:00 New Revision: d812488d3c54c07f24d4bef79e329f17e7f19c3b
URL: https://github.com/llvm/llvm-project/commit/d812488d3c54c07f24d4bef79e329f17e7f19c3b DIFF: https://github.com/llvm/llvm-project/commit/d812488d3c54c07f24d4bef79e329f17e7f19c3b.diff LOG: Call MarkVirtualMembersReferenced on an actual class definition ...rather than on potentially just a declaration. Without the fix, the newly added clang/test/SemaCXX/warn-undefined-internal.cpp failed with > error: 'warning' diagnostics expected but not seen: > File > /home/sbergman/github.com/llvm/llvm-project/clang/test/SemaCXX/warn-undefined-internal.cpp > Line 12 (directive at > /home/sbergman/github.com/llvm/llvm-project/clang/test/SemaCXX/warn-undefined-internal.cpp:13): > function 'test2()::S::f' has internal linkage but is not defined > error: 'note' diagnostics expected but not seen: > File > /home/sbergman/github.com/llvm/llvm-project/clang/test/SemaCXX/warn-undefined-internal.cpp > Line 14 (directive at > /home/sbergman/github.com/llvm/llvm-project/clang/test/SemaCXX/warn-undefined-internal.cpp:15): > used here (I ran into this when two LibreOffice Clang plugins produced false positive warnings, as they relied on Decl::isReferenced() returning true for such virtual member functions of local classes.) Differential Revision: https://reviews.llvm.org/D145123 Added: clang/test/SemaCXX/warn-undefined-internal.cpp Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaDeclCXX.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 7dc80a43e5eb..23a3bbd58b96 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -155,6 +155,8 @@ Improvements to Clang's diagnostics - Clang now warns by default for C++20 and later about deprecated capture of ``this`` with a capture default of ``=``. This warning can be disabled with ``-Wno-deprecated-this-capture``. +- Clang had failed to emit some ``-Wundefined-internal`` for members of a local + class if that class was first introduced with a forward declaration. Bug Fixes in This Version ------------------------- diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index ec85d503ccf8..cf74fcbc4cfa 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -17975,7 +17975,7 @@ void Sema::MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, // 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)); } diff --git a/clang/test/SemaCXX/warn-undefined-internal.cpp b/clang/test/SemaCXX/warn-undefined-internal.cpp new file mode 100644 index 000000000000..81dbbba1d001 --- /dev/null +++ b/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}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits