[clang] f01e8ac - [Clang] Fix handling of zero-length arrays in sfinae context. (#170144)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 2 02:55:48 PST 2025
Author: Corentin Jabot
Date: 2025-12-02T11:55:43+01:00
New Revision: f01e8ac0041da783608029825cb8931f0b9f5b9f
URL: https://github.com/llvm/llvm-project/commit/f01e8ac0041da783608029825cb8931f0b9f5b9f
DIFF: https://github.com/llvm/llvm-project/commit/f01e8ac0041da783608029825cb8931f0b9f5b9f.diff
LOG: [Clang] Fix handling of zero-length arrays in sfinae context. (#170144)
We were producing a diagnostic for zero-length arrays in Sfinae context,
without invalidating the overload.
This causes the diagnostic to be emitted
if and when that undiagnosed overload is selected.
Fixes #170040
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaType.cpp
clang/test/SemaCXX/zero-length-arrays.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9f8d781c93021..54dd8f568eee3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -563,6 +563,7 @@ Bug Fixes to C++ Support
- Fix for clang incorrectly rejecting the default construction of a union with
nontrivial member when another member has an initializer. (#GH81774)
- Fixed a template depth issue when parsing lambdas inside a type constraint. (#GH162092)
+- Fix the support of zero-length arrays in SFINAE context. (#GH170040)
- Diagnose unresolved overload sets in non-dependent compound requirements. (#GH51246) (#GH97753)
- Fix a crash when extracting unavailable member type from alias in template deduction. (#GH165560)
- Fix incorrect diagnostics for lambdas with init-captures inside braced initializers. (#GH163498)
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index aad03d7c1c491..9488a853ffab1 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2261,6 +2261,8 @@ QualType Sema::BuildArrayType(QualType T, ArraySizeModifier ASM,
isSFINAEContext() ? diag::err_typecheck_zero_array_size
: diag::ext_typecheck_zero_array_size)
<< 0 << ArraySize->getSourceRange();
+ if (isSFINAEContext())
+ return QualType();
}
// Is the array too large?
diff --git a/clang/test/SemaCXX/zero-length-arrays.cpp b/clang/test/SemaCXX/zero-length-arrays.cpp
index 0802ec7020463..6bfc7a5fd2e35 100644
--- a/clang/test/SemaCXX/zero-length-arrays.cpp
+++ b/clang/test/SemaCXX/zero-length-arrays.cpp
@@ -1,6 +1,7 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
class Foo {
~Foo();
@@ -19,7 +20,7 @@ class Bar {
Foo foos3[2][0];
public:
- Bar(): foo_count(0) { }
+ Bar(): foo_count(0) { }
~Bar() { }
};
@@ -33,3 +34,17 @@ void testBar() {
#endif
b = b2;
}
+
+namespace GH170040 {
+#if __cplusplus >= 202002L
+template <int N> struct Foo {
+ operator int() const requires(N == 2);
+ template <int I = 0, char (*)[(I)] = nullptr> operator long() const;
+};
+
+void test () {
+ Foo<2> foo;
+ long bar = foo;
+}
+#endif
+}
More information about the cfe-commits
mailing list