[clang] 8f80c66 - [clang] Fix a crash when CTAD fails
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 23 05:04:55 PDT 2021
Author: Kadir Cetinkaya
Date: 2021-03-23T13:03:30+01:00
New Revision: 8f80c66bd2982788a8eede4419684ca72f48b9a2
URL: https://github.com/llvm/llvm-project/commit/8f80c66bd2982788a8eede4419684ca72f48b9a2
DIFF: https://github.com/llvm/llvm-project/commit/8f80c66bd2982788a8eede4419684ca72f48b9a2.diff
LOG: [clang] Fix a crash when CTAD fails
Differential Revision: https://reviews.llvm.org/D99145
Added:
Modified:
clang/lib/Sema/SemaChecking.cpp
clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 46315d3ccaaf7..0570f61458a26 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -4492,7 +4492,8 @@ void Sema::CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl,
// Find expected alignment, and the actual alignment of the passed object.
// getTypeAlignInChars requires complete types
- if (ParamTy->isIncompleteType() || ArgTy->isIncompleteType())
+ if (ParamTy->isIncompleteType() || ArgTy->isIncompleteType() ||
+ ParamTy->isUndeducedType() || ArgTy->isUndeducedType())
return;
CharUnits ParamAlign = Context.getTypeAlignInChars(ParamTy);
diff --git a/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp b/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
index 161944f9e64f6..62b1c166e954c 100644
--- a/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
+++ b/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
@@ -543,6 +543,18 @@ namespace PR47175 {
int m = n<int>;
}
+// Ensure we don't crash when CTAD fails.
+template <typename T1, typename T2>
+struct Foo { // expected-note{{candidate function template not viable}}
+ Foo(T1, T2); // expected-note{{candidate function template not viable}}
+};
+
+template <typename... Args>
+void insert(Args &&...args);
+
+void foo() {
+ insert(Foo(2, 2, 2)); // expected-error{{no viable constructor or deduction guide}}
+}
#else
// expected-no-diagnostics
More information about the cfe-commits
mailing list