Previously we implemented non-standard disambiguation rules to distinguish an enum-base from a bit-field but otherwise treated a : after an elaborated-enum-specifier as introducing an enum-base. That misparses various examples (anywhere an elaborated-type-specifier can appear followed by a colon, such as within a ternary operator or _Generic). We now implement the C++11 rules, with the old cases accepted as extensions where that seemed reasonable. These amount to: * an enum-base must always be accompanied by an enum definition (except in a standalone declaration of the form 'enum E : T;') * in a member-declaration, 'enum E :' always introduces an enum-base, never a bit-field * in a type-specifier (or similar context), 'enum E :' is not permitted; the colon means whatever else it would mean in that context. Fixed underlying types for enums are also permitted in Objective-C and under MS extensions, plus as a language extension in all other modes. The behavior in ObjC and MS extensions modes is unchanged (but the bit-field disambiguation is a bit better); remaining language modes follow the C++11 rules. Fixes PR45726, PR39979, PR19810, PR44941, and most of PR24297, plus C++ core issues 1514 and 1966.
80 lines
2.6 KiB
C++
80 lines
2.6 KiB
C++
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
|
|
|
|
struct global {
|
|
};
|
|
|
|
namespace PR10127 {
|
|
struct outer {
|
|
struct middle {
|
|
struct inner {
|
|
int func();
|
|
int i;
|
|
};
|
|
struct inner2 {
|
|
};
|
|
struct inner3 {
|
|
};
|
|
int mfunc();
|
|
};
|
|
typedef int td_int;
|
|
};
|
|
|
|
struct str {
|
|
operator decltype(outer::middle::inner()) ();
|
|
operator decltype(outer::middle())::inner2 ();
|
|
operator decltype(outer())::middle::inner3 ();
|
|
str(int (decltype(outer::middle::inner())::*n)(),
|
|
int (decltype(outer::middle())::inner::*o)(),
|
|
int (decltype(outer())::middle::inner::*p)());
|
|
};
|
|
|
|
decltype(outer::middle::inner()) a;
|
|
void scope() {
|
|
a.decltype(outer::middle())::mfunc(); // expected-error{{'PR10127::outer::middle::mfunc' is not a member of class 'decltype(outer::middle::inner())'}}
|
|
a.decltype(outer::middle::inner())::func();
|
|
a.decltype(outer::middle())::inner::func();
|
|
a.decltype(outer())::middle::inner::func();
|
|
|
|
a.decltype(outer())::middle::inner::~inner();
|
|
|
|
decltype(outer())::middle::inner().func();
|
|
}
|
|
decltype(outer::middle())::inner b;
|
|
decltype(outer())::middle::inner c;
|
|
decltype(outer())::fail d; // expected-error{{no type named 'fail' in 'PR10127::outer'}}
|
|
decltype(outer())::fail::inner e; // expected-error{{no member named 'fail' in 'PR10127::outer'}}
|
|
decltype()::fail f; // expected-error{{expected expression}}
|
|
decltype()::middle::fail g; // expected-error{{expected expression}}
|
|
|
|
decltype(int()) h;
|
|
decltype(int())::PR10127::outer i; // expected-error{{'decltype(int())' (aka 'int') is not a class, namespace, or enumeration}}
|
|
decltype(int())::global j; // expected-error{{'decltype(int())' (aka 'int') is not a class, namespace, or enumeration}}
|
|
|
|
outer::middle k = decltype(outer())::middle();
|
|
outer::middle::inner l = decltype(outer())::middle::inner();
|
|
|
|
template<typename T>
|
|
struct templ {
|
|
typename decltype(T())::middle::inner x; // expected-error{{type 'decltype(int())' (aka 'int') cannot be used prior to '::' because it has no members}}
|
|
};
|
|
|
|
template class templ<int>; // expected-note{{in instantiation of template class 'PR10127::templ<int>' requested here}}
|
|
template class templ<outer>;
|
|
|
|
enum class foo {
|
|
bar,
|
|
baz
|
|
};
|
|
|
|
foo m = decltype(foo::bar)::baz;
|
|
|
|
enum E {};
|
|
enum H {};
|
|
struct bar {
|
|
enum E : decltype(outer())::td_int(4); // expected-error{{anonymous bit-field}}
|
|
enum F : decltype(outer())::td_int;
|
|
enum G : decltype; // expected-error{{expected '(' after 'decltype'}}
|
|
enum H : 4; // expected-error {{anonymous bit-field}}
|
|
};
|
|
}
|