Skip to content

Commit 125aa10

Browse files
authored
[clang][bytecode] Fix void unary * operators (#105640)
Discard the subexpr.
1 parent 547917a commit 125aa10

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5145,7 +5145,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
51455145
// We should already have a pointer when we get here.
51465146
return this->delegate(SubExpr);
51475147
case UO_Deref: // *x
5148-
if (DiscardResult)
5148+
if (DiscardResult || E->getType()->isVoidType())
51495149
return this->discard(SubExpr);
51505150
return this->visit(SubExpr);
51515151
case UO_Not: // ~x

clang/test/AST/ByteCode/invalid.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %clang_cc1 -fcxx-exceptions -std=c++20 -fexperimental-new-constant-interpreter -verify %s
2-
// RUN: %clang_cc1 -fcxx-exceptions -std=c++20 -verify=ref %s
1+
// RUN: %clang_cc1 -fcxx-exceptions -std=c++20 -fexperimental-new-constant-interpreter -verify=expected,both %s
2+
// RUN: %clang_cc1 -fcxx-exceptions -std=c++20 -verify=ref,both %s
33

44
namespace Throw {
55

@@ -65,4 +65,9 @@ namespace Casts {
6565
// ref-error {{must be initialized by a constant expression}} \
6666
// ref-note {{reinterpret_cast is not allowed}}
6767

68+
void func() {
69+
struct B {};
70+
B b;
71+
(void)*reinterpret_cast<void*>(&b); // both-error {{indirection not permitted on operand of type 'void *'}}
72+
}
6873
}

0 commit comments

Comments
 (0)