Skip to content

Commit f01e8ac

Browse files
authored
[Clang] Fix handling of zero-length arrays in sfinae context. (llvm#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 llvm#170040
1 parent 437fa02 commit f01e8ac

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ Bug Fixes to C++ Support
563563
- Fix for clang incorrectly rejecting the default construction of a union with
564564
nontrivial member when another member has an initializer. (#GH81774)
565565
- Fixed a template depth issue when parsing lambdas inside a type constraint. (#GH162092)
566+
- Fix the support of zero-length arrays in SFINAE context. (#GH170040)
566567
- Diagnose unresolved overload sets in non-dependent compound requirements. (#GH51246) (#GH97753)
567568
- Fix a crash when extracting unavailable member type from alias in template deduction. (#GH165560)
568569
- Fix incorrect diagnostics for lambdas with init-captures inside braced initializers. (#GH163498)

clang/lib/Sema/SemaType.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,6 +2261,8 @@ QualType Sema::BuildArrayType(QualType T, ArraySizeModifier ASM,
22612261
isSFINAEContext() ? diag::err_typecheck_zero_array_size
22622262
: diag::ext_typecheck_zero_array_size)
22632263
<< 0 << ArraySize->getSourceRange();
2264+
if (isSFINAEContext())
2265+
return QualType();
22642266
}
22652267

22662268
// Is the array too large?

clang/test/SemaCXX/zero-length-arrays.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify %s
22
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
33
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
45

56
class Foo {
67
~Foo();
@@ -19,7 +20,7 @@ class Bar {
1920
Foo foos3[2][0];
2021

2122
public:
22-
Bar(): foo_count(0) { }
23+
Bar(): foo_count(0) { }
2324
~Bar() { }
2425
};
2526

@@ -33,3 +34,17 @@ void testBar() {
3334
#endif
3435
b = b2;
3536
}
37+
38+
namespace GH170040 {
39+
#if __cplusplus >= 202002L
40+
template <int N> struct Foo {
41+
operator int() const requires(N == 2);
42+
template <int I = 0, char (*)[(I)] = nullptr> operator long() const;
43+
};
44+
45+
void test () {
46+
Foo<2> foo;
47+
long bar = foo;
48+
}
49+
#endif
50+
}

0 commit comments

Comments
 (0)