Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/AST/ByteCode/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ bool GetGlobal(InterpState &S, CodePtr OpPC, uint32_t I) {
template <PrimType Name, class T = typename PrimConv<Name>::T>
bool GetGlobalUnchecked(InterpState &S, CodePtr OpPC, uint32_t I) {
const Pointer &Ptr = S.P.getPtrGlobal(I);
if (!Ptr.isInitialized())
if (!CheckInitialized(S, OpPC, Ptr, AK_Read))
return false;
S.Stk.push<T>(Ptr.deref<T>());
return true;
Expand Down
8 changes: 8 additions & 0 deletions clang/test/AST/ByteCode/cxx11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,11 @@ namespace DynamicCast {
int g : (S*)(void*)(sptr) == sptr;
};
}

namespace GlobalInitializer {
extern int &g; // both-note {{here}}
struct S {
int G : g; // both-error {{constant expression}} \
// both-note {{initializer of 'g' is unknown}}
};
}
17 changes: 9 additions & 8 deletions clang/test/SemaCXX/constant-expression-p2280r4.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %clang_cc1 -std=c++23 -verify=expected,nointerpreter %s
// RUN: %clang_cc1 -std=c++23 -verify %s -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -std=c++23 -verify %s
// RUN: %clang_cc1 -std=c++23 -verify=expected,interpreter %s -fexperimental-new-constant-interpreter

using size_t = decltype(sizeof(0));

Expand Down Expand Up @@ -48,10 +48,11 @@ void splash(Swim& swam) {
}

extern Swim dc;
extern Swim& trident;
extern Swim& trident; // interpreter-note {{declared here}}

constexpr auto& sandeno = typeid(dc); // ok: can only be typeid(Swim)
constexpr auto& gallagher = typeid(trident); // expected-error {{constexpr variable 'gallagher' must be initialized by a constant expression}}
constexpr auto& gallagher = typeid(trident); // expected-error {{constexpr variable 'gallagher' must be initialized by a constant expression}} \
// interpreter-note {{initializer of 'trident' is unknown}}

namespace explicitThis {
struct C {
Expand Down Expand Up @@ -157,18 +158,18 @@ int g() {

namespace GH128409 {
int &ff();
int &x = ff(); // nointerpreter-note {{declared here}}
int &x = ff(); // expected-note {{declared here}}
constinit int &z = x; // expected-error {{variable does not have a constant initializer}} \
// expected-note {{required by 'constinit' specifier here}} \
// nointerpreter-note {{initializer of 'x' is not a constant expression}}
// expected-note {{initializer of 'x' is not a constant expression}}
}

namespace GH129845 {
int &ff();
int &x = ff(); // nointerpreter-note {{declared here}}
int &x = ff(); // expected-note {{declared here}}
struct A { int& x; };
constexpr A g = {x}; // expected-error {{constexpr variable 'g' must be initialized by a constant expression}} \
// nointerpreter-note {{initializer of 'x' is not a constant expression}}
// expected-note {{initializer of 'x' is not a constant expression}}
const A* gg = &g;
}

Expand Down
Loading