[clang] ef1bb11 - [clang][Parse] Fix crash when emitting template diagnostic

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 30 06:12:51 PDT 2022


Author: Timm Bäder
Date: 2022-08-30T15:11:38+02:00
New Revision: ef1bb11a34de2822514878b99b442575a022a658

URL: https://github.com/llvm/llvm-project/commit/ef1bb11a34de2822514878b99b442575a022a658
DIFF: https://github.com/llvm/llvm-project/commit/ef1bb11a34de2822514878b99b442575a022a658.diff

LOG: [clang][Parse] Fix crash when emitting template diagnostic

This was passing a 6 to the diagnostic engine, which the diagnostic
message didn't handle.

Add the new value to the diagnosic message, remove an unused value and
add a test.

This fixes https://github.com/llvm/llvm-project/issues/57415

Differential Revision: https://reviews.llvm.org/D132821

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/include/clang/Basic/DiagnosticParseKinds.td
    clang/test/Parser/cxx-concept-declaration.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 92b52b8998b4f..54060deca5c30 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -84,6 +84,8 @@ Bug Fixes
 - Fix assert that triggers a crash during template name lookup when a type was
   incomplete but was not also a TagType. This fixes
   `Issue 57387 <https://github.com/llvm/llvm-project/issues/57387>`_.
+- Fix a crash when emitting a concept-related diagnostic. This fixes
+  `Issue 57415 <https://github.com/llvm/llvm-project/issues/57415>`_.
 
 
 Improvements to Clang's diagnostics

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 18adb21e2be08..84504b15764b1 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -775,7 +775,8 @@ def warn_cxx14_compat_template_template_param_typename : Warning<
 def err_template_spec_syntax_non_template : Error<
   "identifier followed by '<' indicates a class template specialization but "
   "%0 %select{does not refer to a template|refers to a function template|"
-  "<unused>|refers to a variable template|<unused>|refers to a concept}1">;
+  "<unused>|refers to a variable template|<unused>|<unused>|"
+  "refers to a concept}1">;
 def err_id_after_template_in_nested_name_spec : Error<
   "expected template name after 'template' keyword in nested name specifier">;
 def err_unexpected_template_in_unqualified_id : Error<

diff  --git a/clang/test/Parser/cxx-concept-declaration.cpp b/clang/test/Parser/cxx-concept-declaration.cpp
index 41bf53aed36e5..9248e26b9cbeb 100644
--- a/clang/test/Parser/cxx-concept-declaration.cpp
+++ b/clang/test/Parser/cxx-concept-declaration.cpp
@@ -1,7 +1,12 @@
 
 // Support parsing of concepts
 // Disabled for now.
-// expected-no-diagnostics
 
-// RUN:  %clang_cc1 -std=c++14 -x c++ -verify %s
-// template<typename T> concept C1 = true;
+// RUN:  %clang_cc1 -std=c++20 -x c++ -verify %s
+template<typename T> concept C1 = true;
+
+template<class T>
+concept C = true;
+
+template<class T>
+class C<int> {}; //expected-error{{identifier followed by '<' indicates a class template specialization but 'C' refers to a concept}}


        


More information about the cfe-commits mailing list