Tests for DR370-380.

Also promote a couple of Warnings on ill-formed code found by this testing to
ExtWarns.

llvm-svn: 203021
This commit is contained in:
Richard Smith 2014-03-05 22:54:58 +00:00
parent 6b9cf961bd
commit faf156ad15
6 changed files with 125 additions and 17 deletions

View File

@ -41,6 +41,7 @@ def SignConversion : DiagGroup<"sign-conversion">;
def BoolConversion : DiagGroup<"bool-conversion">;
def IntConversion : DiagGroup<"int-conversion">;
def EnumConversion : DiagGroup<"enum-conversion">;
def EnumTooLarge : DiagGroup<"enum-too-large">;
def NonLiteralNullConversion : DiagGroup<"non-literal-null-conversion">;
def NullConversion : DiagGroup<"null-conversion">;
def ImplicitConversionFloatingPointToBool :

View File

@ -3774,10 +3774,11 @@ def warn_ivars_in_interface : Warning<
def ext_enum_value_not_int : Extension<
"ISO C restricts enumerator values to range of 'int' (%0 is too "
"%select{small|large}1)">;
def warn_enum_too_large : Warning<
"enumeration values exceed range of largest integer">;
def warn_enumerator_too_large : Warning<
"enumerator value %0 is not representable in the largest integer type">;
def ext_enum_too_large : ExtWarn<
"enumeration values exceed range of largest integer">, InGroup<EnumTooLarge>;
def ext_enumerator_increment_too_large : ExtWarn<
"incremented enumerator value %0 is not representable in the "
"largest integer type">, InGroup<EnumTooLarge>;
def warn_illegal_constant_array_size : Extension<
"size of static array must be an integer constant expression">;

View File

@ -12452,7 +12452,7 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum,
<< EnumVal.toString(10)
<< EltTy;
else
Diag(IdLoc, diag::warn_enumerator_too_large)
Diag(IdLoc, diag::ext_enumerator_increment_too_large)
<< EnumVal.toString(10);
} else {
EltTy = T;
@ -12850,7 +12850,7 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc,
BestWidth = Context.getTargetInfo().getLongLongWidth();
if (NumNegativeBits > BestWidth || NumPositiveBits >= BestWidth)
Diag(Enum->getLocation(), diag::warn_enum_too_large);
Diag(Enum->getLocation(), diag::ext_enum_too_large);
BestType = Context.LongLongTy;
}
}

View File

@ -816,3 +816,111 @@ namespace dr368 { // dr368: yes
}
// dr370: na
namespace dr372 { // dr372: no
namespace example1 {
template<typename T> struct X {
protected:
typedef T Type; // expected-note 2{{protected}}
};
template<typename T> struct Y {};
// FIXME: These two are valid; deriving from T1<T> gives Z1 access to
// the protected member T1<T>::Type.
template<typename T,
template<typename> class T1,
template<typename> class T2> struct Z1 :
T1<T>,
T2<typename T1<T>::Type> {}; // expected-error {{protected}}
template<typename T,
template<typename> class T1,
template<typename> class T2> struct Z2 :
T2<typename T1<T>::Type>, // expected-error {{protected}}
T1<T> {};
Z1<int, X, Y> z1; // expected-note {{instantiation of}}
Z2<int, X, Y> z2; // expected-note {{instantiation of}}
}
namespace example2 {
struct X {
private:
typedef int Type; // expected-note {{private}}
};
template<typename T> struct A {
typename T::Type t; // expected-error {{private}}
};
A<X> ax; // expected-note {{instantiation of}}
}
namespace example3 {
struct A {
protected:
typedef int N; // expected-note 2{{protected}}
};
template<typename T> struct B {};
template<typename U> struct C : U, B<typename U::N> {}; // expected-error {{protected}}
template<typename U> struct D : B<typename U::N>, U {}; // expected-error {{protected}}
C<A> x; // expected-note {{instantiation of}}
D<A> y; // expected-note {{instantiation of}}
}
namespace example4 {
class A {
class B {};
friend class X;
};
struct X : A::B {
A::B mx;
class Y {
A::B my;
};
};
}
}
namespace dr373 { // dr373: no
// FIXME: This is valid.
namespace X { int dr373; } // expected-note 2{{here}}
struct dr373 { // expected-note {{here}}
void f() {
using namespace dr373::X; // expected-error {{no namespace named 'X' in 'dr373::dr373'}}
int k = dr373; // expected-error {{does not refer to a value}}
namespace Y = dr373::X; // expected-error {{no namespace named 'X' in 'dr373::dr373'}}
k = Y::dr373;
}
};
}
namespace dr374 { // dr374: yes c++11
namespace N {
template<typename T> void f();
template<typename T> struct A { void f(); };
}
template<> void N::f<char>() {}
template<> void N::A<char>::f() {}
template<> struct N::A<int> {};
#if __cplusplus < 201103L
// expected-error@-4 {{extension}} expected-note@-7 {{here}}
// expected-error@-4 {{extension}} expected-note@-7 {{here}}
// expected-error@-4 {{extension}} expected-note@-8 {{here}}
#endif
}
// dr375: dup 345
// dr376: na
namespace dr377 { // dr377: yes
enum E { // expected-error {{enumeration values exceed range of largest integer}}
a = -__LONG_LONG_MAX__ - 1, // expected-error 0-1{{extension}}
b = 2 * (unsigned long long)__LONG_LONG_MAX__ // expected-error 0-2{{extension}}
};
}
// dr378: dup 276
// dr379: na

View File

@ -18,7 +18,7 @@ This test serves two purposes:
The list of warnings below should NEVER grow. It should gradually shrink to 0.
CHECK: Warnings without flags (111):
CHECK: Warnings without flags (109):
CHECK-NEXT: ext_delete_void_ptr_operand
CHECK-NEXT: ext_expected_semi_decl_list
CHECK-NEXT: ext_explicit_specialization_storage_class
@ -69,9 +69,7 @@ CHECK-NEXT: warn_drv_objc_gc_unsupported
CHECK-NEXT: warn_drv_pch_not_first_include
CHECK-NEXT: warn_dup_category_def
CHECK-NEXT: warn_duplicate_protocol_def
CHECK-NEXT: warn_enum_too_large
CHECK-NEXT: warn_enum_value_overflow
CHECK-NEXT: warn_enumerator_too_large
CHECK-NEXT: warn_exception_caught_by_earlier_handler
CHECK-NEXT: warn_excess_initializers
CHECK-NEXT: warn_excess_initializers_in_char_array_initializer

View File

@ -2273,49 +2273,49 @@ of class templates</td>
<td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#372">372</a></td>
<td>CD1</td>
<td>Is access granted by base class specifiers available in following base class specifiers?</td>
<td class="none" align="center">Unknown</td>
<td class="none" align="center">No</td>
</tr>
<tr>
<td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#373">373</a></td>
<td>C++11</td>
<td>Lookup on namespace qualified name in using-directive</td>
<td class="none" align="center">Unknown</td>
<td class="none" align="center">No</td>
</tr>
<tr>
<td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#374">374</a></td>
<td>CD2</td>
<td>Can explicit specialization outside namespace use qualified name?</td>
<td class="none" align="center">Unknown</td>
<td class="full" align="center">Yes (C++11 onwards)</td>
</tr>
<tr>
<td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#375">375</a></td>
<td>dup</td>
<td>Confusing example on lookup with <TT>typename</TT></td>
<td class="none" align="center">Unknown</td>
<td class="full" align="center">Duplicate of 345</td>
</tr>
<tr>
<td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#376">376</a></td>
<td>NAD</td>
<td>Class "definition" versus class "declaration"</td>
<td class="none" align="center">Unknown</td>
<td class="na" align="center">N/A</td>
</tr>
<tr>
<td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#377">377</a></td>
<td>CD1</td>
<td>Enum whose enumerators will not fit in any integral type</td>
<td class="none" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr>
<td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#378">378</a></td>
<td>CD1</td>
<td>Wording that says temporaries are declared</td>
<td class="none" align="center">Unknown</td>
<td class="na" align="center">Duplicate of 276</td>
</tr>
<tr>
<td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#379">379</a></td>
<td>CD1</td>
<td>Change "class declaration" to "class definition"</td>
<td class="none" align="center">Unknown</td>
<td class="na" align="center">N/A</td>
</tr>
<tr class="open">
<td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#380">380</a></td>