https://github.com/cor3ntin created https://github.com/llvm/llvm-project/pull/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 >From 9a7dd58c33492837bf77a82d02600b1e016e5754 Mon Sep 17 00:00:00 2001 From: Corentin Jabot <[email protected]> Date: Mon, 1 Dec 2025 14:57:53 +0100 Subject: [PATCH] [Clang] Fix handling of zero-length arrays in sfinae context. 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 --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaType.cpp | 2 ++ clang/test/SemaCXX/zero-length-arrays.cpp | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8161ccdffca82..33ea81e4352c4 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -554,6 +554,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 eb8b1352d1be1..91cc4eb4b1016 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -2259,6 +2259,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 +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
