Fix a crash on an invalid templated UDL declaration

We were missing a null pointer check that a template parameter existed
at all.
This commit is contained in:
Aaron Ballman 2021-10-15 09:56:54 -04:00
parent 4a9bcb605b
commit f2ea852550
2 changed files with 7 additions and 1 deletions

View File

@ -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>()))

View File

@ -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();
}