Files
clang-p2996/clang/test/CXX/basic/basic.lookup/basic.lookup.elab/p2.cpp
Reid Kleckner 1a4ab7e772 Improve error message when referencing a non-tag type with a tag
Other compilers accept invalid code here that we reject, and we need a
better error message to try to convince users that the code is really
incorrect. Consider:
  class Foo {
    typedef MyIterHelper<Foo> iterator;
    friend class iterator;
  };

Previously our wording was "elaborated type refers to a typedef".
"elaborated type" isn't widely known terminology, so the new diagnostic
says "typedef 'iterator' cannot be referenced with class specifier".

Reviewers: rsmith

Differential Revision: https://reviews.llvm.org/D25216

llvm-svn: 289259
2016-12-09 19:47:58 +00:00

61 lines
1.0 KiB
C++

// RUN: %clang_cc1 -fsyntax-only -verify %s
namespace test0 {
struct A {
static int foo;
};
namespace i0 {
typedef int A; // expected-note {{declared here}}
int test() {
struct A a; // expected-error {{typedef 'A' cannot be referenced with a struct specifier}}
return a.foo;
}
}
namespace i1 {
template <class> class A; // expected-note {{declared here}}
int test() {
struct A a; // expected-error {{template 'A' cannot be referenced with a struct specifier}}
return a.foo;
}
}
namespace i2 {
int A;
int test() {
struct A a;
return a.foo;
}
}
namespace i3 {
void A();
int test() {
struct A a;
return a.foo;
}
}
namespace i4 {
template <class T> void A();
int test() {
struct A a;
return a.foo;
}
}
// This should magically be okay; see comment in SemaDecl.cpp.
// rdar://problem/7898108
typedef struct A A;
int test() {
struct A a;
return a.foo;
}
}