-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
void h() {
int i1 = 0;
const int i4 = 0;
extern void h4(int x = sizeof(i4)); // ok, not odr-use
extern void h5(int x = decltype(i4 + 4)()); // ok, not odr-use
+
+ union {
+ int i5;
+ };
+
+ extern void h6(int = i5);
+ // expected-error@-1 {{default argument references local variable '' of enclosing function}}
+
+ struct S { int i; };
+ auto [x] = S();
+
+ extern void h7(int = x); // FIXME: reject
}
namespace ns_unused { typedef int Int_unused __attribute__((unused)); }
namespace ns_not_unused { typedef int Int_not_unused; }
+template <typename T> class C;
+template <> class __attribute__((unused)) C<int> {};
+
void f() {
ns_not_unused::Int_not_unused i1; // expected-warning {{unused variable}}
ns_unused::Int_unused i0; // expected-warning {{'Int_unused' was marked unused but was used}}
+
+ union __attribute__((unused)) { // expected-warning {{'' was marked unused but was used}}
+ int i;
+ };
+ (void) i;
+
+ C<int>(); // expected-warning {{'C' was marked unused but was used}}
}
static int f(int = 10); // expected-note{{default argument declared here}}
};
+template <typename T> class C3;
+template <> class C3<int> {
+ static void g(int = f()); // expected-error {{use of default argument to function 'f' that is declared later in class 'C3'}}
+ static int f(int = 10); // expected-note {{default argument declared here}}
+};
+
// Make sure we actually parse the default argument for an inline definition
class XX {
void A(int length = -1 ) { }
// RUN: %clang_cc1 -fsyntax-only -verify %s
-struct A; // expected-note 14 {{forward declaration of 'A'}}
+struct A; // expected-note 15 {{forward declaration of 'A'}}
A f(); // expected-note {{'f' declared here}}
+template <typename T> A ft(T); // expected-note {{'ft' declared here}}
struct B {
A f(); // expected-note {{'f' declared here}}
A (B::*mfp)() = 0;
(b.*mfp)(); // expected-error {{calling function with incomplete return type 'A'}}
-
+
+ ft(42); // expected-error {{calling 'ft' with incomplete return type 'A'}}
}
void operator_parens() {
[&](int x){ operator()(); }(0); // expected-error {{undeclared 'operator()'}}
}
+
+namespace captured_name {
+void Test() {
+ union { // expected-note {{'' declared here}}
+ int i;
+ };
+ [] { return i; }; // expected-error {{variable '' cannot be implicitly captured in a lambda with no capture-default specified}}
+ // expected-note@-1 {{lambda expression begins here}}
+
+}
+};