[PATCH] D131662: [clang] Try to improve diagnostics about uninitialized constexpr variables
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 18 10:04:03 PDT 2022
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.
LGTM, though you should add a release note.
================
Comment at: clang/lib/Sema/SemaInit.cpp:8057
+ const Decl *D = Entity.getDecl();
+ const VarDecl *VD = dyn_cast_or_null<VarDecl>(D);
+ QualType DestType = Entity.getType();
----------------
================
Comment at: clang/lib/Sema/SemaInit.cpp:8063
// handled in the Failed() branch above.
- QualType DestType = Entity.getType();
- S.Diag(Kind.getLocation(), DiagID)
- << DestType << (bool)DestType->getAs<RecordType>()
- << FixItHint::CreateInsertion(ZeroInitializationFixitLoc,
- ZeroInitializationFixit);
+ if (!DestType->getAs<RecordType>() && VD && VD->isConstexpr()) {
+ // Use a more useful diagnostic for constexpr variables.
----------------
================
Comment at: clang/lib/Sema/SemaInit.cpp:9477
<< Entity.getName();
+ } else if (const auto *VD = dyn_cast_if_present<VarDecl>(Entity.getDecl());
+ VD && VD->isConstexpr()) {
----------------
Oh, neato, I see `dyn_cast_or_null` was deprecated...
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131662/new/
https://reviews.llvm.org/D131662
More information about the cfe-commits
mailing list