[clang] [clang] more useful error message for decomposition declaration missing initializer (PR #127924)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 20 05:23:01 PST 2025
================
@@ -14058,7 +14058,17 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl) {
// C++1z [dcl.dcl]p1 grammar implies that an initializer is mandatory.
if (isa<DecompositionDecl>(RealDecl)) {
- Diag(Var->getLocation(), diag::err_decomp_decl_requires_init) << Var;
+ Preprocessor &PP = getPreprocessor();
+ SourceManager &SM = Context.getSourceManager();
+ LangOptions LO = Context.getLangOpts();
+
+ // Lexer previously checked for '=' and didn't find it
+ // Highlight the token found in its place in the error message
+ Token Tok;
+ Lexer::getRawToken(PP.getLastCachedTokenLocation(), Tok, SM, LO);
----------------
erichkeane wrote:
This whole bit here with the raw-token isn't right, and shouldn't be in Sema. We also can't count on the preprocessors 'last location' with templates, since we'll be at end of TU.
Same with the `getSpelling` part. If we want to improve this diagnostic, we need tog et the information from the AST somehow.
https://github.com/llvm/llvm-project/pull/127924
More information about the cfe-commits
mailing list