[clang] f2ea852 - Fix a crash on an invalid templated UDL declaration
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 15 07:00:25 PDT 2021
Author: Aaron Ballman
Date: 2021-10-15T10:00:16-04:00
New Revision: f2ea85255075606563370c9249f61dfad6a3f98b
URL: https://github.com/llvm/llvm-project/commit/f2ea85255075606563370c9249f61dfad6a3f98b
DIFF: https://github.com/llvm/llvm-project/commit/f2ea85255075606563370c9249f61dfad6a3f98b.diff
LOG: Fix a crash on an invalid templated UDL declaration
We were missing a null pointer check that a template parameter existed
at all.
Added:
Modified:
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/literal-operators.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 31eda99089295..2d1fd1b14040f 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -15908,7 +15908,7 @@ checkLiteralOperatorTemplateParameterList(Sema &SemaRef,
//
// As a DR resolution, we also allow placeholders for deduced class
// template specializations.
- if (SemaRef.getLangOpts().CPlusPlus20 &&
+ if (SemaRef.getLangOpts().CPlusPlus20 && PmDecl &&
!PmDecl->isTemplateParameterPack() &&
(PmDecl->getType()->isRecordType() ||
PmDecl->getType()->getAs<DeducedTemplateSpecializationType>()))
diff --git a/clang/test/SemaCXX/literal-operators.cpp b/clang/test/SemaCXX/literal-operators.cpp
index 834d5ec7923e6..067e151606202 100644
--- a/clang/test/SemaCXX/literal-operators.cpp
+++ b/clang/test/SemaCXX/literal-operators.cpp
@@ -51,3 +51,9 @@ void test_if_2() { "foo"if; } // expected-error {{no matching literal operator f
template<typename T> void dependent_member_template() {
T().template operator""_foo<int>(); // expected-error {{'operator""_foo' following the 'template' keyword cannot refer to a dependent template}}
}
+
+namespace PR51142 {
+// This code previously crashed due to a null template parameter declaration.
+template<typename T> // expected-error {{template parameter list for literal operator must be either 'char...' or 'typename T, T...'}}
+constexpr auto operator ""_l();
+}
More information about the cfe-commits
mailing list