[PATCH] D127638: [clang][sema] Provide better diagnostic for missing template parameters

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 15 07:06:31 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc149fa1f5fda: [clang][sema] Provide better diagnostic for missing template arguments (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D127638?vs=436690&id=437145#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127638

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/test/SemaCXX/nested-name-spec.cpp


Index: clang/test/SemaCXX/nested-name-spec.cpp
===================================================================
--- clang/test/SemaCXX/nested-name-spec.cpp
+++ clang/test/SemaCXX/nested-name-spec.cpp
@@ -473,3 +473,10 @@
     x: goto x;
   }
 }
+
+template <typename T>
+struct x; // expected-note {{template is declared here}}
+
+template <typename T>
+int issue55962 = x::a; // expected-error {{use of class template 'x' requires template arguments}} \
+                       // expected-warning {{variable templates are a C++14 extension}}
Index: clang/lib/Sema/SemaCXXScopeSpec.cpp
===================================================================
--- clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -828,10 +828,14 @@
   }
 
   if (!Found.empty()) {
-    if (TypeDecl *TD = Found.getAsSingle<TypeDecl>())
+    if (TypeDecl *TD = Found.getAsSingle<TypeDecl>()) {
       Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
           << Context.getTypeDeclType(TD) << getLangOpts().CPlusPlus;
-    else {
+    } else if (Found.getAsSingle<TemplateDecl>()) {
+      ParsedType SuggestedType;
+      DiagnoseUnknownTypeName(IdInfo.Identifier, IdInfo.IdentifierLoc, S, &SS,
+                              SuggestedType);
+    } else {
       Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
           << IdInfo.Identifier << getLangOpts().CPlusPlus;
       if (NamedDecl *ND = Found.getAsSingle<NamedDecl>())
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -264,7 +264,9 @@
 - ``-Wshift-overflow`` will not warn for signed left shifts in C++20 mode
   (and newer), as it will always wrap and never overflow. This fixes
   `Issue 52873 <https://github.com/llvm/llvm-project/issues/52873>`_.
-
+- When using class templates without arguments, clang now tells developers
+  that template arguments are missing in certain contexts.
+  This fixes `Issue 55962 <https://github.com/llvm/llvm-project/issues/55962>`_.
 
 Non-comprehensive list of changes in this release
 -------------------------------------------------


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127638.437145.patch
Type: text/x-patch
Size: 2205 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220615/aef1c955/attachment-0001.bin>


More information about the cfe-commits mailing list