[clang] 5b949a6 - Fix crash when diagnosing a CTAD failure in an array new expression
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 18 11:02:02 PDT 2021
Author: Aaron Ballman
Date: 2021-10-18T14:01:55-04:00
New Revision: 5b949a649aff0406a878e8eb8d7d5efba0a55e4a
URL: https://github.com/llvm/llvm-project/commit/5b949a649aff0406a878e8eb8d7d5efba0a55e4a
DIFF: https://github.com/llvm/llvm-project/commit/5b949a649aff0406a878e8eb8d7d5efba0a55e4a.diff
LOG: Fix crash when diagnosing a CTAD failure in an array new expression
This appears to be a think-o where the developer was trying to check for a null
pointer but was actually checking (redundantly) whether the optional held a
valid value or not. We now properly check the pointer for null.
This fixes PR51547.
Added:
clang/test/SemaCXX/new-delete-array.cpp
Modified:
clang/lib/Sema/SemaExprCXX.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 6b091364c911f..0f3f50c8f6c6f 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1967,10 +1967,10 @@ Sema::BuildCXXNew(SourceRange Range, bool UseGlobal,
if (Deduced && isa<DeducedTemplateSpecializationType>(Deduced)) {
if (ArraySize)
return ExprError(
- Diag(ArraySize ? (*ArraySize)->getExprLoc() : TypeRange.getBegin(),
+ Diag(*ArraySize ? (*ArraySize)->getExprLoc() : TypeRange.getBegin(),
diag::err_deduced_class_template_compound_type)
<< /*array*/ 2
- << (ArraySize ? (*ArraySize)->getSourceRange() : TypeRange));
+ << (*ArraySize ? (*ArraySize)->getSourceRange() : TypeRange));
InitializedEntity Entity
= InitializedEntity::InitializeNew(StartLoc, AllocType);
diff --git a/clang/test/SemaCXX/new-delete-array.cpp b/clang/test/SemaCXX/new-delete-array.cpp
new file mode 100644
index 0000000000000..fca1ec132acca
--- /dev/null
+++ b/clang/test/SemaCXX/new-delete-array.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 %s -verify=cxx17
+// RUN: %clang_cc1 -fsyntax-only -std=c++14 %s -verify=cxx14
+
+namespace PR51547 {
+template<class> struct A; // cxx14-note {{template is declared here}}
+auto p = new A[]{}; // cxx14-error {{use of class template 'A' requires template arguments}} \
+ cxx17-error {{cannot form array of deduced class template specialization type}}
+}
+
More information about the cfe-commits
mailing list