[clang] [clang][Parser] "Better" error messages for invalid template template (PR #95726)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 17 03:09:09 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 9f69e116a55dbd36e2f4fde38317de7262c88d7c 44620330cd5238de549d3d77ddc447cd3bc51e60 -- clang/lib/Parse/ParseTemplate.cpp clang/test/CXX/drs/cwg1xx.cpp clang/test/Parser/cxx-template-decl.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp
index e5308d9eda..858a22f43a 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -787,18 +787,17 @@ NamedDecl *Parser::ParseTemplateTemplateParameter(unsigned Depth,
unsigned Position) {
assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
- if (Token ahead = GetLookAheadToken(1);
- ahead.isOneOf(tok::identifier, tok::ellipsis,
- tok::equal, tok::comma,
- tok::greater, tok::greatergreater, tok::greatergreatergreater)) {
- // Maybe they intended `typename` instead of `template` (given thats more common)
- // Error early, to add a fixit hint
+ if (Token ahead = GetLookAheadToken(1); ahead.isOneOf(
+ tok::identifier, tok::ellipsis, tok::equal, tok::comma, tok::greater,
+ tok::greatergreater, tok::greatergreatergreater)) {
+ // Maybe they intended `typename` instead of `template` (given thats more
+ // common) Error early, to add a fixit hint
Diag(ahead.getLocation(), diag::err_expected_less_after) << "template";
-
+
Diag(Tok.getLocation(), diag::note_meant_to_use_typename)
- << FixItHint::CreateReplacement(CharSourceRange::getTokenRange(Tok.getLocation()),
- "typename");
+ << FixItHint::CreateReplacement(
+ CharSourceRange::getTokenRange(Tok.getLocation()), "typename");
Tok.setKind(tok::kw_typename);
return ParseTypeParameter(Depth, Position);
``````````
</details>
https://github.com/llvm/llvm-project/pull/95726
More information about the cfe-commits
mailing list