[PATCH] D131662: [clang] Try to improve diagnostics about uninitialized constexpr variables

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 17 21:55:53 PDT 2022


tbaeder marked an inline comment as done.
tbaeder added inline comments.


================
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.
----------------
aaron.ballman wrote:
> Why the check for a record type?
For record types, the current error message would be:
```
default initialization of an object of const type 'const S3' without a user-provided default constructor
```
which gives more information than just "must be initialized by a constant expression".


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131662/new/

https://reviews.llvm.org/D131662



More information about the cfe-commits mailing list