[clang] 0947296 - [Sema][SVE] Reject sizeless types in exception specs
Richard Sandiford via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 17 04:45:04 PDT 2020
Author: Richard Sandiford
Date: 2020-03-17T11:39:03Z
New Revision: 0947296902075aaa240d78f66aa0708f825ffb35
URL: https://github.com/llvm/llvm-project/commit/0947296902075aaa240d78f66aa0708f825ffb35
DIFF: https://github.com/llvm/llvm-project/commit/0947296902075aaa240d78f66aa0708f825ffb35.diff
LOG: [Sema][SVE] Reject sizeless types in exception specs
In the current SVE ACLE spec, the usual rules for throwing and
catching incomplete types also apply to sizeless types. However,
throwing pointers to sizeless types should not pose any real difficulty,
so as an extension, the clang implementation allows that.
This patch enforces these rules for explicit exception specs.
Differential Revision: https://reviews.llvm.org/D76087
Added:
Modified:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExceptionSpec.cpp
clang/test/SemaCXX/sizeless-1.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1d32bc547905..b33e11e79604 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1537,6 +1537,9 @@ def err_distant_exception_spec : Error<
def err_incomplete_in_exception_spec : Error<
"%select{|pointer to |reference to }0incomplete type %1 is not allowed "
"in exception specification">;
+def err_sizeless_in_exception_spec : Error<
+ "%select{|reference to }0sizeless type %1 is not allowed "
+ "in exception specification">;
def ext_incomplete_in_exception_spec : ExtWarn<err_incomplete_in_exception_spec.Text>,
InGroup<MicrosoftExceptionSpec>;
def err_rref_in_exception_spec : Error<
diff --git a/clang/lib/Sema/SemaExceptionSpec.cpp b/clang/lib/Sema/SemaExceptionSpec.cpp
index 1e892aa622df..5c9844e1cd28 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -167,6 +167,14 @@ bool Sema::CheckSpecifiedExceptionType(QualType &T, SourceRange Range) {
RequireCompleteType(Range.getBegin(), PointeeT, DiagID, Kind, Range))
return ReturnValueOnError;
+ // The MSVC compatibility mode doesn't extend to sizeless types,
+ // so diagnose them separately.
+ if (PointeeT->isSizelessType() && Kind != 1) {
+ Diag(Range.getBegin(), diag::err_sizeless_in_exception_spec)
+ << (Kind == 2 ? 1 : 0) << PointeeT << Range;
+ return true;
+ }
+
return false;
}
diff --git a/clang/test/SemaCXX/sizeless-1.cpp b/clang/test/SemaCXX/sizeless-1.cpp
index b13b862f5fab..876f5931a7db 100644
--- a/clang/test/SemaCXX/sizeless-1.cpp
+++ b/clang/test/SemaCXX/sizeless-1.cpp
@@ -345,6 +345,12 @@ void with_default(svint8_t = svint8_t());
constexpr int ce_taking_int8(svint8_t) { return 1; } // expected-error {{constexpr function's 1st parameter type 'svint8_t' (aka '__SVInt8_t') is not a literal type}}
#endif
+#if __cplusplus < 201703L
+void throwing_func() throw(svint8_t); // expected-error {{sizeless type 'svint8_t' (aka '__SVInt8_t') is not allowed in exception specification}}
+void throwing_pointer_func() throw(svint8_t *);
+void throwing_reference_func() throw(svint8_t &); // expected-error {{reference to sizeless type 'svint8_t' (aka '__SVInt8_t') is not allowed in exception specification}}
+#endif
+
template <typename T>
void template_fn_direct(T) {}
template <typename T>
More information about the cfe-commits
mailing list