Skip to content

Commit f7a74ec

Browse files
authored
[clang][bytecode] Diagnose array-to-pointer decays of dummy pointers (#106366)
We have type information for them now, so we can do this.
1 parent 94ed47f commit f7a74ec

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

clang/lib/AST/ByteCode/Interp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2537,7 +2537,7 @@ inline bool ArrayDecay(InterpState &S, CodePtr OpPC) {
25372537
if (!CheckRange(S, OpPC, Ptr, CSK_ArrayToPointer))
25382538
return false;
25392539

2540-
if (Ptr.isRoot() || !Ptr.isUnknownSizeArray() || Ptr.isDummy()) {
2540+
if (Ptr.isRoot() || !Ptr.isUnknownSizeArray()) {
25412541
S.Stk.push<Pointer>(Ptr.atIndex(0));
25422542
return true;
25432543
}

clang/test/AST/ByteCode/arrays.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,15 @@ namespace Incomplete {
436436
constexpr int C = *F.a; // both-error {{must be initialized by a constant expression}} \
437437
// both-note {{array-to-pointer decay of array member without known bound}}
438438

439+
struct X {
440+
int a;
441+
int b[];
442+
};
443+
extern X x;
444+
constexpr int *xb = x.b; // both-error {{must be initialized by a constant expression}} \
445+
// both-note {{array-to-pointer decay of array member without known bound}}
446+
447+
439448
/// These are from test/SemaCXX/constant-expression-cxx11.cpp
440449
extern int arr[];
441450
constexpr int *c = &arr[1]; // both-error {{must be initialized by a constant expression}} \

0 commit comments

Comments
 (0)