[clang] 2c00b3b - [clang][bytecode] Silently reject ctors of invalid decls (#128290)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 21 23:01:59 PST 2025
Author: Timm Baeder
Date: 2025-02-22T08:01:56+01:00
New Revision: 2c00b3b859d9fca6d5565af7b3f4574013c7330e
URL: https://github.com/llvm/llvm-project/commit/2c00b3b859d9fca6d5565af7b3f4574013c7330e
DIFF: https://github.com/llvm/llvm-project/commit/2c00b3b859d9fca6d5565af7b3f4574013c7330e.diff
LOG: [clang][bytecode] Silently reject ctors of invalid decls (#128290)
The follow-up diagnostic would otherwise be:
array.cpp:111:33: note: undefined constructor '(unnamed struct at
array.cpp:111:11)' cannot be used in a constant expression
array.cpp:111:11: note: declared here
111 | constexpr struct { Unknown U; } InvalidCtor;
| ^
... and complaining about the undefined constructor of a class that is
invalid anyway doesn't make much sense.
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 c07690a3d941c..dfa59a50b2711 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -732,6 +732,11 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
DiagDecl = CD = Inherited;
}
+ // Silently reject constructors of invalid classes. The invalid class
+ // has been rejected elsewhere before.
+ if (CD && CD->getParent()->isInvalidDecl())
+ return false;
+
// FIXME: If DiagDecl is an implicitly-declared special member function
// or an inheriting constructor, we should be much more explicit about why
// it's not constexpr.
diff --git a/clang/test/AST/ByteCode/records.cpp b/clang/test/AST/ByteCode/records.cpp
index a13f30cd23119..608b94e55560a 100644
--- a/clang/test/AST/ByteCode/records.cpp
+++ b/clang/test/AST/ByteCode/records.cpp
@@ -1734,3 +1734,8 @@ namespace DeadUpcast {
static_assert(foo(), "");
}
#endif
+
+namespace CtorOfInvalidClass {
+ constexpr struct { Unknown U; } InvalidCtor; // both-error {{unknown type name 'Unknown'}} \
+ // both-error {{must be initialized by a constant expression}}
+}
More information about the cfe-commits
mailing list