Skip to content

Commit bca3cea

Browse files
committed
[Clang] Don't check incomplete CXXRecordDecl's members when transforming sizeof...(expr)
For a FunctionParmPackExpr that is used as the argument of a sizeof...(pack) expression, we might exercise the logic that checks the CXXRecordDecl's members regardless of the type being incomplete, when rebuilding the DeclRefExpr into non-ODR-used forms.
1 parent e0ea9fd commit bca3cea

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ Bug Fixes to C++ Support
796796
- Fixed an assertion failure caused by using ``consteval`` in condition in consumed analyses. (#GH117385)
797797
- Fix a crash caused by incorrect argument position in merging deduced template arguments. (#GH113659)
798798
- Fixed a parser crash when using pack indexing as a nested name specifier. (#GH119072)
799+
- Fixed a null pointer dereference issue when heuristically computing ``sizeof...(pack)`` expressions. (#GH81436)
799800
- Fixed an assertion failure caused by mangled names with invalid identifiers. (#GH112205)
800801
- Fixed an incorrect lambda scope of generic lambdas that caused Clang to crash when computing potential lambda
801802
captures at the end of a full expression. (#GH115931)

clang/lib/Sema/SemaExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19297,7 +19297,7 @@ static ExprResult rebuildPotentialResultsAsNonOdrUsed(Sema &S, Expr *E,
1929719297
if (VD->getType()->isReferenceType())
1929819298
return true;
1929919299
if (auto *RD = VD->getType()->getAsCXXRecordDecl())
19300-
if (RD->hasMutableFields())
19300+
if (RD->hasDefinition() && RD->hasMutableFields())
1930119301
return true;
1930219302
if (!VD->isUsableInConstantExpressions(S.Context))
1930319303
return true;

clang/test/CXX/temp/temp.decls/temp.variadic/sizeofpack.cpp

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

44
namespace pr12262 {
@@ -201,3 +201,22 @@ void func()
201201
}
202202

203203
}
204+
205+
namespace GH81436 {
206+
207+
template <class E> struct Bar;
208+
209+
template <class E>
210+
Bar(E) -> Bar<E>;
211+
212+
template <int> struct Foo {};
213+
214+
// Bar<Ts> doesn't have to be of a complete type.
215+
template <class... Ts>
216+
auto func() requires requires(Bar<Ts> ...init_lists) {
217+
sizeof...(init_lists) > 0;
218+
} {}
219+
220+
void f() { func<int>(); }
221+
222+
} // namespace GH81436

0 commit comments

Comments
 (0)