xref: /llvm-project/clang/test/AST/ByteCode/weak.cpp (revision d267daa9eb517b2e040a59121c15dba59223ebba)
1a07aba5dSTimm Baeder // RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter -verify=expected,both %s
2a07aba5dSTimm Baeder // RUN: %clang_cc1 -std=c++20 -verify=ref,both %s
3a07aba5dSTimm Baeder 
4a07aba5dSTimm Baeder [[gnu::weak]] extern int a;
5a07aba5dSTimm Baeder int ha[(bool)&a]; // both-warning {{variable length arrays in C++ are a Clang extension}} \
6a07aba5dSTimm Baeder                   // both-error {{variable length array declaration not allowed at file scope}}
7a07aba5dSTimm Baeder int ha2[&a == nullptr]; // both-warning {{variable length arrays in C++ are a Clang extension}} \
8a07aba5dSTimm Baeder                         // both-note {{comparison against address of weak declaration '&a' can only be performed at runtime}} \
9a07aba5dSTimm Baeder                         // both-error {{variable length array declaration not allowed at file scope}}
10*d267daa9STimm Baeder 
11*d267daa9STimm Baeder extern const int W1 __attribute__((weak)) = 10; // both-note {{declared here}}
12*d267daa9STimm Baeder static_assert(W1 == 10, ""); // both-error {{static assertion expression is not an integral constant expression}} \
13*d267daa9STimm Baeder                              // both-note {{initializer of weak variable 'W1' is not considered constant because it may be different at runtime}}
14*d267daa9STimm Baeder 
15*d267daa9STimm Baeder extern const int W2 __attribute__((weak)); // both-note {{declared here}}
16*d267daa9STimm Baeder static_assert(W2 == 10, ""); // both-error {{static assertion expression is not an integral constant expression}} \
17*d267daa9STimm Baeder                              // both-note {{initializer of 'W2' is unknown}}
18