Skip to content

Commit 2c00b3b

Browse files
authored
[clang][bytecode] Silently reject ctors of invalid decls (llvm#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.
1 parent c645981 commit 2c00b3b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,11 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
732732
DiagDecl = CD = Inherited;
733733
}
734734

735+
// Silently reject constructors of invalid classes. The invalid class
736+
// has been rejected elsewhere before.
737+
if (CD && CD->getParent()->isInvalidDecl())
738+
return false;
739+
735740
// FIXME: If DiagDecl is an implicitly-declared special member function
736741
// or an inheriting constructor, we should be much more explicit about why
737742
// it's not constexpr.

clang/test/AST/ByteCode/records.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,3 +1734,8 @@ namespace DeadUpcast {
17341734
static_assert(foo(), "");
17351735
}
17361736
#endif
1737+
1738+
namespace CtorOfInvalidClass {
1739+
constexpr struct { Unknown U; } InvalidCtor; // both-error {{unknown type name 'Unknown'}} \
1740+
// both-error {{must be initialized by a constant expression}}
1741+
}

0 commit comments

Comments
 (0)