Skip to content

Commit 6db96c9

Browse files
authored
[clang][bytecode] Always reject ctors of invalid parent decls (#128295)
The copy constructor of an invalid declaration might still be perfectly valid, but we still need to reject it.
1 parent f404047 commit 6db96c9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,8 +1238,10 @@ static bool checkConstructor(InterpState &S, CodePtr OpPC, const Function *Func,
12381238
const Pointer &ThisPtr) {
12391239
assert(Func->isConstructor());
12401240

1241-
const Descriptor *D = ThisPtr.getFieldDesc();
1241+
if (Func->getParentDecl()->isInvalidDecl())
1242+
return false;
12421243

1244+
const Descriptor *D = ThisPtr.getFieldDesc();
12431245
// FIXME: I think this case is not 100% correct. E.g. a pointer into a
12441246
// subobject of a composite array.
12451247
if (!D->ElemRecord)

clang/test/AST/ByteCode/records.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,4 +1738,12 @@ namespace DeadUpcast {
17381738
namespace CtorOfInvalidClass {
17391739
constexpr struct { Unknown U; } InvalidCtor; // both-error {{unknown type name 'Unknown'}} \
17401740
// both-error {{must be initialized by a constant expression}}
1741+
1742+
#if __cplusplus >= 202002L
1743+
template <typename T, auto Q>
1744+
concept ReferenceOf = Q;
1745+
/// This calls a valid and constexpr copy constructor of InvalidCtor,
1746+
/// but should still be rejected.
1747+
template<ReferenceOf<InvalidCtor> auto R, typename Rep> int F; // both-error {{non-type template argument is not a constant expression}}
1748+
#endif
17411749
}

0 commit comments

Comments
 (0)