[clang] 6db96c9 - [clang][bytecode] Always reject ctors of invalid parent decls (#128295)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 22 13:04:47 PST 2025
Author: Timm Baeder
Date: 2025-02-22T22:04:44+01:00
New Revision: 6db96c9ecc781c742f546d2863632d44e9c9b435
URL: https://github.com/llvm/llvm-project/commit/6db96c9ecc781c742f546d2863632d44e9c9b435
DIFF: https://github.com/llvm/llvm-project/commit/6db96c9ecc781c742f546d2863632d44e9c9b435.diff
LOG: [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.
Added:
Modified:
clang/lib/AST/ByteCode/Interp.cpp
clang/test/AST/ByteCode/records.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index dfa59a50b2711..e383828cd676d 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1238,8 +1238,10 @@ static bool checkConstructor(InterpState &S, CodePtr OpPC, const Function *Func,
const Pointer &ThisPtr) {
assert(Func->isConstructor());
- const Descriptor *D = ThisPtr.getFieldDesc();
+ if (Func->getParentDecl()->isInvalidDecl())
+ return false;
+ const Descriptor *D = ThisPtr.getFieldDesc();
// FIXME: I think this case is not 100% correct. E.g. a pointer into a
// subobject of a composite array.
if (!D->ElemRecord)
diff --git a/clang/test/AST/ByteCode/records.cpp b/clang/test/AST/ByteCode/records.cpp
index 608b94e55560a..cb3d6111fd2bf 100644
--- a/clang/test/AST/ByteCode/records.cpp
+++ b/clang/test/AST/ByteCode/records.cpp
@@ -1738,4 +1738,12 @@ namespace DeadUpcast {
namespace CtorOfInvalidClass {
constexpr struct { Unknown U; } InvalidCtor; // both-error {{unknown type name 'Unknown'}} \
// both-error {{must be initialized by a constant expression}}
+
+#if __cplusplus >= 202002L
+ template <typename T, auto Q>
+ concept ReferenceOf = Q;
+ /// This calls a valid and constexpr copy constructor of InvalidCtor,
+ /// but should still be rejected.
+ template<ReferenceOf<InvalidCtor> auto R, typename Rep> int F; // both-error {{non-type template argument is not a constant expression}}
+#endif
}
More information about the cfe-commits
mailing list