Skip to content

Commit

Permalink
[clang][NFC] Tests showing the problems with some uses of NamedDecl::…
Browse files Browse the repository at this point in the history
…getDeclName in diagnostics, SemaExpr.cpp part
  • Loading branch information
riccibruno committed Jul 18, 2020
1 parent 32db24a commit be8e5fe
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
14 changes: 13 additions & 1 deletion clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
@@ -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;
Expand All @@ -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
}
10 changes: 10 additions & 0 deletions clang/test/SemaCXX/attr-unused.cpp
Expand Up @@ -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}}
}
6 changes: 6 additions & 0 deletions clang/test/SemaCXX/default2.cpp
Expand Up @@ -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 ) { }
Expand Down
6 changes: 4 additions & 2 deletions clang/test/SemaCXX/incomplete-call.cpp
@@ -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}}
Expand Down Expand Up @@ -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'}}
}


Expand Down
11 changes: 11 additions & 0 deletions clang/test/SemaCXX/lambda-expressions.cpp
Expand Up @@ -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}}

}
};

0 comments on commit be8e5fe

Please sign in to comment.