This is an archive of the discontinued LLVM Phabricator instance.

[Sema] `setInvalidDecl` for error deduction declaration
ClosedPublic

Authored by HerrCai0907 on Apr 29 2023, 2:59 AM.

Diff Detail

Event Timeline

HerrCai0907 created this revision.Apr 29 2023, 2:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 29 2023, 2:59 AM
HerrCai0907 requested review of this revision.Apr 29 2023, 2:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 29 2023, 2:59 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

add release note

Thank you for the fix.

I have some questions, why don't we always call CheckDeductionGuideDeclarator when calling CXXDeductionGuideDecl::Create, I felt like perhaps CheckDeductionGuideDeclarator should be rolled into CXXDeductionGuideDecl::Create but then I noticed they are not paired up in other locations.

CC @rsmith

I wonder if there are any cases where the "deduction guide" is so broken that we shouldn't be creating a CXXDeductionGuideDecl at all. For example, if there's no trailing return type, then the declaration is syntactically invalid (and looks more like a constructor than a deduction guide), and it's not clear to me whether creating a CXXDeductionGuideDecl really makes sense.

I have some questions, why don't we always call CheckDeductionGuideDeclarator when calling CXXDeductionGuideDecl::Create, I felt like perhaps CheckDeductionGuideDeclarator should be rolled into CXXDeductionGuideDecl::Create but then I noticed they are not paired up in other locations.

CXXDeductionGuideDecl::Create is the low-level AST primitive for creating a CXXDeductionGuideDecl. The responsibility for validating the declaration and issuing diagnostics doesn't belong at that level, it belongs in Sema. The other callers are:

  • When Sema creates an implicit deduction guide from a constructor. In this case Sema knows it's valid by construction.
  • When Sema instantiates a deduction guide. In this case Sema knows it's valid because the template was.
clang/lib/Sema/SemaDecl.cpp
9201–9202

This is reversed from the normal Clang convention (where true indicates that an error was produced).

9204

Use auto here.

clang/lib/Sema/SemaDeclCXX.cpp
11153–11154

Can we just return immediately here? I don't see a reason to keep going -- this error may well indicate that the developer didn't actually mean to declare a deduction guide in the first place, so the diagnostic on a function body below is likely to not be useful.

11205–11206

Should we return that we had an error after this one too?

HerrCai0907 marked an inline comment as done.

refactor

HerrCai0907 marked 2 inline comments as done.Apr 30 2023, 10:48 PM
HerrCai0907 added inline comments.
clang/lib/Sema/SemaDeclCXX.cpp
11205–11206

if D.isFunctionDefinition(), we can still create valid deduction guide. I think keeping it can avoid lots of meaningless error later.

Fznamznon added inline comments.
clang/lib/Sema/SemaDeclCXX.cpp
11153–11154

NIT: You can also just do return Diag(...) here and in other places. This is equal to return true.

return Diag

This comment was removed by HerrCai0907.

@rsmith could you review it again?

aaron.ballman accepted this revision.May 22 2023, 2:07 PM

LGTM aside from a request for a comment.

clang/lib/Sema/SemaDeclCXX.cpp
11205–11206

I think it's worth leaving that as a comment in the code so folks know it's done on purpose and why.

This revision is now accepted and ready to land.May 22 2023, 2:07 PM

update comment

This revision was landed with ongoing or failed builds.May 23 2023, 12:08 AM
This revision was automatically updated to reflect the committed changes.
dyung added a subscriber: dyung.May 23 2023, 1:10 AM

Hi @HerrCai0907, this change is failing on the PS4 linux and PS5 Windows bot. Can you take a look? I'm guessing these failures are likely due to the PS4/PS5 target defaulting to a different C/C++ standard than the rest of clang.

https://lab.llvm.org/buildbot/#/builders/139/builds/41248
https://lab.llvm.org/buildbot/#/builders/216/builds/21637

The build bot failures have been going for a while now so I've had to revert this until the author can address them, my apologies.

This revision is now accepted and ready to land.May 23 2023, 11:52 AM

add std option

This revision was landed with ongoing or failed builds.May 23 2023, 1:16 PM
This revision was automatically updated to reflect the committed changes.