================
@@ -0,0 +1,347 @@
+// RUN: %clang_cc1 -std=c23 -triple x86_64-unknown-linux-gnu -verify
-fsyntax-only %s
+// RUN: %clang_cc1 -std=c23 -triple x86_64-unknown-linux-gnu -verify
-fsyntax-only -fexperimental-new-constant-interpreter %s
+// RUN: %clang_cc1 -std=c23 -triple x86_64-scei-ps4 -verify=expected,ps4
-fsyntax-only %s
+
+#define M static
+struct S { int a; char b; };
+int f1(void);
+
+void test1(void) {
+ (void)(constexpr int){1};
+ (void)&(static int){42};
+ (void)(register int){0};
+ (void)(static thread_local int){1};
+ (void)(static __thread int){2};
+ (void)(constexpr struct S){1, 'a'};
+ (void)(static struct S){2, 'b'};
+ (void)(register struct S){3, 'c'};
+}
+
+void test2(void) {
+ (void)(static constexpr int){1};
+ (void)(constexpr static int){2};
+ (void)(static thread_local int){3};
+ (void)(thread_local static int){4};
+ (void)(constexpr register int){5};
+ (void)(constexpr static thread_local int){6}; // expected-error {{cannot
combine with previous '_Thread_local' declaration specifier}}
+}
+
+void test3(void) {
+ (void)(static static int){1}; // expected-warning {{duplicate
'static' declaration specifier}}
+ (void)(constexpr constexpr int){2}; // expected-warning {{duplicate
'constexpr' declaration specifier}}
+ (void)(register register int){3}; // expected-warning {{duplicate
'register' declaration specifier}}
+ (void)(thread_local thread_local int){4}; // expected-warning {{duplicate
'_Thread_local' declaration specifier}} expected-error {{compound literal with
'thread_local' storage duration at block scope must also specify 'static'}}
+}
+
+void test4(void) {
+ (void)(register static int){1}; // expected-error {{cannot combine
with previous 'register' declaration specifier}}
+ (void)(register thread_local int){2}; // expected-error {{cannot combine
with previous 'register' declaration specifier}}
+ (void)(register constexpr int){3};
+ (void)(static register int){4}; // expected-error {{cannot combine
with previous 'static' declaration specifier}}
+ (void)(register _Atomic int){5};
+}
+
+void test5(void) {
+ (void)&(thread_local int){1}; // expected-error {{compound literal with
'thread_local' storage duration at block scope must also specify 'static'}}
+}
+
+int *a1 = &(register int){42}; // expected-error {{file scope compound literal
specifies 'register'}}
+
+void test6(void) {
+ (void)(constexpr volatile int){1}; // expected-error {{constexpr variable
cannot have type 'const volatile int'}}
+ (void)(constexpr _Atomic int){1}; // expected-error {{constexpr variable
cannot have type 'const _Atomic(int)'}}
+
+ int c;
+ (void)(constexpr int[c]){0}; // expected-error {{constexpr variable cannot
have type 'const int[c]'}}
+}
+
+void test7(void) {
+ (void)(constexpr int){f1()}; // expected-error {{initializer of
compound literal must be a constant expression}}
+ (void)(static int){f1()}; // expected-error {{initializer
element is not a compile-time constant}}
+ (void)(register constexpr int){f1()}; // expected-error {{initializer of
compound literal must be a constant expression}}
+ (void)(constexpr int){1 / 0};
+ // expected-error@-1 {{initializer of compound literal must be a constant
expression}}
+ // expected-note@-2 {{division by zero}}
+ // expected-warning@-3 {{division by zero is undefined}}
+}
+
+const int a2 = 1;
+const double a3 = 1.0;
+
+void test8(void) {
+ (void)(constexpr int){a2}; // expected-error {{initializer of compound
literal must be a constant expression}}
+ (void)(constexpr double){a3}; // expected-error {{initializer of compound
literal must be a constant expression}}
+
+ const int a = 2;
+ (void)(constexpr int){a}; // expected-error {{initializer of compound
literal must be a constant expression}}
+
+ struct S1 {
+ int a;
+ };
+
+ (void)(constexpr int){(constexpr int){1}};
+ (void)(constexpr struct S1){.a = (constexpr int){1}};
+ (void)(constexpr int){(int){1}};
+ (void)(constexpr int){(static int){1}};
----------------
nickdesaulniers wrote:
Accepting but flagging via `-Wpedantic` seems like a good compromise.
https://github.com/llvm/llvm-project/pull/212559
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits