zequanwu created this revision. zequanwu added a reviewer: hans. Herald added a project: clang. Herald added a subscriber: cfe-commits. zequanwu requested review of this revision.
I think one note to speficify the forward declaretion location should be enough. Two notes might be too noisy. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D85390 Files: clang/lib/Sema/SemaInit.cpp clang/test/Modules/namespaces.cpp clang/test/SemaCXX/elaborated-type-specifier.cpp Index: clang/test/SemaCXX/elaborated-type-specifier.cpp =================================================================== --- clang/test/SemaCXX/elaborated-type-specifier.cpp +++ clang/test/SemaCXX/elaborated-type-specifier.cpp @@ -26,7 +26,7 @@ } void test_X_elab(NS::X x) { - struct S4 *s4 = 0; + struct S4 *s4 = 0; // expected-note{{forward declaration of 'S4'}} x.test_elab2(s4); // expected-error{{cannot initialize a parameter of type 'NS::S4 *' with an lvalue of type 'struct S4 *'}} } Index: clang/test/Modules/namespaces.cpp =================================================================== --- clang/test/Modules/namespaces.cpp +++ clang/test/Modules/namespaces.cpp @@ -78,7 +78,8 @@ // expected-note@Inputs/namespaces-right.h:60 {{passing argument to parameter here}} // expected-note@Inputs/namespaces-right.h:67 {{passing argument to parameter here}} - +// expected-note@Inputs/namespaces-left.h:63 {{forward declaration of 'N11::(anonymous namespace)::Foo'}} +// expected-note@Inputs/namespaces-left.h:70 {{forward declaration of 'N12::(anonymous namespace)::Foo'}} // Test that bringing in one name from an overload set does not hide the rest. void testPartialImportOfOverloadSet() { void (*p)() = N13::p; Index: clang/lib/Sema/SemaInit.cpp =================================================================== --- clang/lib/Sema/SemaInit.cpp +++ clang/lib/Sema/SemaInit.cpp @@ -8707,6 +8707,12 @@ if (entity.getKind() == InitializedEntity::EK_Result) S.EmitRelatedResultTypeNoteForReturn(destType); } + QualType fromType = op->getType(); + auto *fromDecl = fromType.getTypePtr()->getPointeeCXXRecordDecl(); + if (fromDecl && !fromDecl->hasDefinition() && !fromDecl->isInvalidDecl() && + fromDecl->getDeclKind() == Decl::CXXRecord) + S.Diag(fromDecl->getLocation(), diag::note_forward_declaration) + << S.getASTContext().getTagDeclType(fromDecl); } static void diagnoseListInit(Sema &S, const InitializedEntity &Entity,
Index: clang/test/SemaCXX/elaborated-type-specifier.cpp =================================================================== --- clang/test/SemaCXX/elaborated-type-specifier.cpp +++ clang/test/SemaCXX/elaborated-type-specifier.cpp @@ -26,7 +26,7 @@ } void test_X_elab(NS::X x) { - struct S4 *s4 = 0; + struct S4 *s4 = 0; // expected-note{{forward declaration of 'S4'}} x.test_elab2(s4); // expected-error{{cannot initialize a parameter of type 'NS::S4 *' with an lvalue of type 'struct S4 *'}} } Index: clang/test/Modules/namespaces.cpp =================================================================== --- clang/test/Modules/namespaces.cpp +++ clang/test/Modules/namespaces.cpp @@ -78,7 +78,8 @@ // expected-note@Inputs/namespaces-right.h:60 {{passing argument to parameter here}} // expected-note@Inputs/namespaces-right.h:67 {{passing argument to parameter here}} - +// expected-note@Inputs/namespaces-left.h:63 {{forward declaration of 'N11::(anonymous namespace)::Foo'}} +// expected-note@Inputs/namespaces-left.h:70 {{forward declaration of 'N12::(anonymous namespace)::Foo'}} // Test that bringing in one name from an overload set does not hide the rest. void testPartialImportOfOverloadSet() { void (*p)() = N13::p; Index: clang/lib/Sema/SemaInit.cpp =================================================================== --- clang/lib/Sema/SemaInit.cpp +++ clang/lib/Sema/SemaInit.cpp @@ -8707,6 +8707,12 @@ if (entity.getKind() == InitializedEntity::EK_Result) S.EmitRelatedResultTypeNoteForReturn(destType); } + QualType fromType = op->getType(); + auto *fromDecl = fromType.getTypePtr()->getPointeeCXXRecordDecl(); + if (fromDecl && !fromDecl->hasDefinition() && !fromDecl->isInvalidDecl() && + fromDecl->getDeclKind() == Decl::CXXRecord) + S.Diag(fromDecl->getLocation(), diag::note_forward_declaration) + << S.getASTContext().getTagDeclType(fromDecl); } static void diagnoseListInit(Sema &S, const InitializedEntity &Entity,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits