This is an archive of the discontinued LLVM Phabricator instance.

[clang][sema] Provide better diagnostic for missing template parameters
ClosedPublic

Authored by tbaeder on Jun 13 2022, 7:25 AM.

Details

Summary

This fixes https://github.com/llvm/llvm-project/issues/55962

i.e. instead of the output being

./test.cpp:5:9: error: 'x' is not a class, namespace, or enumeration
int y = x::a;
        ^
./test.cpp:2:8: note: 'x' declared here
struct x;
       ^
1 error generated.

it is now:

./test.cpp:5:9: error: use of class template 'x' requires template arguments
int y = x::a;
        ^
./test.cpp:2:8: note: template is declared here
struct x;
       ^
1 error generated.

Note that the call to isTemplateName() is basically copied from DiagnoseUnknownTypeName() in SemaDecl.cpp. However, just calling that from SemaCXXScopeSpec.cpp as well makes the SemaObjCXX/property-dot-error.mm test fail, because it now outputs

clang/test/SemaObjCXX/propert-dot-error.mm Line 67: unknown type name 'D'; did you mean 'D'?
clang/test/SemaObjCXX/propert-dot-error.mm Line 68: unknown type name 'D'; did you mean 'D'?

and I don't know enough about objc to fix this, but if anyone has some pointers I'd be happy to avoid the code duplication.

Diff Detail

Event Timeline

tbaeder created this revision.Jun 13 2022, 7:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 13 2022, 7:25 AM
tbaeder requested review of this revision.Jun 13 2022, 7:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 13 2022, 7:25 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Note that the call to isTemplateName() is basically copied from DiagnoseUnknownTypeName() in SemaDecl.cpp. However, just calling that from SemaCXXScopeSpec.cpp as well makes the SemaObjCXX/property-dot-error.mm test fail, because it now outputs
clang/test/SemaObjCXX/propert-dot-error.mm Line 67: unknown type name 'D'; did you mean 'D'?
clang/test/SemaObjCXX/propert-dot-error.mm Line 68: unknown type name 'D'; did you mean 'D'?
and I don't know enough about objc to fix this, but if anyone has some pointers I'd be happy to avoid the code duplication.

Perhaps one way around that is to test else if (TemplateDecl *TD = Found.getAsSingle<TemplateDecl>()) {} before calling DiagnoseUnknownTypeName()?

tbaeder updated this revision to Diff 436650.Jun 13 2022, 10:13 PM

That does indeed work, thanks for the suggestion!

tbaeder updated this revision to Diff 436690.Jun 14 2022, 1:10 AM
aaron.ballman accepted this revision.Jun 14 2022, 3:50 AM

LGTM, thanks for the fix! Please add a release note when you land the changes. :-)

This revision is now accepted and ready to land.Jun 14 2022, 3:50 AM
This revision was landed with ongoing or failed builds.Jun 15 2022, 7:06 AM
This revision was automatically updated to reflect the committed changes.