xref: /llvm-project/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp (revision 742970920b7a7fc2fe1cb6bca6fb04f03ab7d5d9)
1 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
2 
h()3 void h() {
4   int i1 = 0;
5   extern void h1(int x = i1);
6   // expected-error@-1 {{default argument references local variable 'i1' of enclosing function}}
7 
8   const int i2 = 0;
9   extern void h2a(int x = i2);     // ok, not odr-use
10   extern void h2b(int x = i2 + 0); // ok, not odr-use
11 
12   const int i3 = 0;
13   extern void h3(const int *x = &i3);
14   // expected-error@-1 {{default argument references local variable 'i3' of enclosing function}}
15 
16   const int i4 = 0;
17   extern void h4(int x = sizeof(i4));         // ok, not odr-use
18   extern void h5(int x = decltype(i4 + 4)()); // ok, not odr-use
19 
20   union {
21     int i5;
22   };
23 
24   extern void h6(int = i5);
25   // expected-error@-1 {{default argument references local variable '' of enclosing function}}
26 
27   struct S { int i; };
28   auto [x] = S();
29 
30   extern void h7(int = x);
31   // expected-error@-1 {{default argument references local variable 'x' of enclosing function}}
32 
33 }
34