aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Parse/ParseDecl.cpp
diff options
context:
space:
mode:
authorErich Keane <erich.keane@intel.com>2022-11-01 11:37:35 -0700
committerErich Keane <erich.keane@intel.com>2022-11-01 11:39:46 -0700
commitab4c22e2b735c839c667e08be303f7f8cef3ccf6 (patch)
treef76e7cd419d2e7360048b39f3c2c64a74f5bf7fb /clang/lib/Parse/ParseDecl.cpp
parent00022c5613a7490148ae1147e25a695fc59c5f92 (diff)
downloadllvm-ab4c22e2b735c839c667e08be303f7f8cef3ccf6.zip
llvm-ab4c22e2b735c839c667e08be303f7f8cef3ccf6.tar.gz
llvm-ab4c22e2b735c839c667e08be303f7f8cef3ccf6.tar.bz2
[Concepts] Improve diagnostics on a missing 'auto' keyword.
As reported in https://github.com/llvm/llvm-project/issues/49192, we did a pretty poor job diagnosing cases where someone forgot 'auto', a nd is probably in the middle of a variable declaration. This patch makes us properly diagnose in cases where the next token is a reference, or CVR qualifier.
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r--clang/lib/Parse/ParseDecl.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index fd35898..d7942fa 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3706,11 +3706,18 @@ void Parser::ParseDeclarationSpecifiers(
if (TemplateId->Kind == TNK_Concept_template) {
// If we've already diagnosed that this type-constraint has invalid
- // arguemnts, drop it and just form 'auto' or 'decltype(auto)'.
+ // arguments, drop it and just form 'auto' or 'decltype(auto)'.
if (TemplateId->hasInvalidArgs())
TemplateId = nullptr;
- if (NextToken().is(tok::identifier)) {
+ // Any of the following tokens are likely the start of the user
+ // forgetting 'auto' or 'decltype(auto)', so diagnose.
+ // Note: if updating this list, please make sure we update
+ // isCXXDeclarationSpecifier's check for IsPlaceholderSpecifier to have
+ // a matching list.
+ if (NextToken().isOneOf(tok::identifier, tok::kw_const,
+ tok::kw_volatile, tok::kw_restrict, tok::amp,
+ tok::ampamp)) {
Diag(Loc, diag::err_placeholder_expected_auto_or_decltype_auto)
<< FixItHint::CreateInsertion(NextToken().getLocation(), "auto");
// Attempt to continue as if 'auto' was placed here.