This is an archive of the discontinued LLVM Phabricator instance.

[clang] Evaluate non-type default template argument when it is required
ClosedPublic

Authored by Fznamznon on May 8 2023, 3:56 AM.

Details

Summary

Before this change a default template argument for a non-type template
parameter was evaluated and checked immediately after it is met by
parser. In some cases it is too early.

Fixes https://github.com/llvm/llvm-project/issues/62224
Fixes https://github.com/llvm/llvm-project/issues/62596

Diff Detail

Event Timeline

Fznamznon created this revision.May 8 2023, 3:56 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: arphaman. · View Herald Transcript
Fznamznon requested review of this revision.May 8 2023, 3:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 8 2023, 3:56 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tbaeder added inline comments.May 8 2023, 4:31 AM
clang/docs/ReleaseNotes.rst
380
cor3ntin accepted this revision.May 8 2023, 5:02 AM

LGTM. I love it when remove it code fixes a bug!
Thanks for the PR

This revision is now accepted and ready to land.May 8 2023, 5:02 AM
erichkeane accepted this revision.May 8 2023, 7:19 AM
shafik added inline comments.May 8 2023, 8:03 AM
clang/lib/Sema/SemaTemplate.cpp
1613

Out of curiosity where is the template argument being checked now and why does checking it early cause the failure?

Fznamznon added inline comments.May 8 2023, 8:26 AM
clang/lib/Sema/SemaTemplate.cpp
1613

After the patch template argument is checked when the template is instantiated, i.e. the check now happens together for the whole provided template argument list.
Early checking causes reject-valid problems when for example a function is forward declared, used in default template argument and then defined later but before the point of instantiation. With early check the error also would be emitted if default template argument was never used.

shafik accepted this revision.May 8 2023, 10:13 AM