[clang][NFC] Tests showing the problems with some uses of NamedDecl::getDeclName in diagnostics, SemaExpr.cpp part

This commit is contained in:
Bruno Ricci 2020-07-18 20:39:16 +01:00
parent 32db24a7f2
commit be8e5fee91
No known key found for this signature in database
GPG Key ID: D58C906B2F684D92
5 changed files with 44 additions and 3 deletions

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
void h() {
int i1 = 0;
@ -16,4 +16,16 @@ void h() {
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
}

View File

@ -3,7 +3,17 @@
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}}
}

View File

@ -117,6 +117,12 @@ class C2 {
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 ) { }

View File

@ -1,7 +1,8 @@
// 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}}
@ -38,7 +39,8 @@ void g() {
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'}}
}

View File

@ -649,3 +649,14 @@ void Run(const int& points) {
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}}
}
};