Skip to content

Commit d44518c

Browse files
authored
[Clang] Don't check incomplete CXXRecordDecl's members when transforming sizeof...(expr) (#119344)
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. Fixes #81436
1 parent e8baa79 commit d44518c

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ Bug Fixes to C++ Support
805805
- Fixed an assertion failure caused by using ``consteval`` in condition in consumed analyses. (#GH117385)
806806
- Fix a crash caused by incorrect argument position in merging deduced template arguments. (#GH113659)
807807
- Fixed a parser crash when using pack indexing as a nested name specifier. (#GH119072)
808+
- Fixed a null pointer dereference issue when heuristically computing ``sizeof...(pack)`` expressions. (#GH81436)
808809
- Fixed an assertion failure caused by mangled names with invalid identifiers. (#GH112205)
809810
- Fixed an incorrect lambda scope of generic lambdas that caused Clang to crash when computing potential lambda
810811
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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2+
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
23
// expected-no-diagnostics
34

45
namespace pr12262 {
@@ -201,3 +202,24 @@ void func()
201202
}
202203

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

0 commit comments

Comments
 (0)