forked from OSchip/llvm-project
-Wc++98-compat and -Wc++98-compat-pedantic warnings for Sema, part 2.
llvm-svn: 142426
This commit is contained in:
parent
c1939d3967
commit
c82397332d
|
@ -622,8 +622,14 @@ def err_unexpected_friend : Error<
|
||||||
"friends can only be classes or functions">;
|
"friends can only be classes or functions">;
|
||||||
def ext_enum_friend : ExtWarn<
|
def ext_enum_friend : ExtWarn<
|
||||||
"enumeration type %0 cannot be a friend">;
|
"enumeration type %0 cannot be a friend">;
|
||||||
|
def warn_cxx98_compat_enum_friend : Warning<
|
||||||
|
"befriending enumeration type %0 is incompatible with C++98">,
|
||||||
|
InGroup<CXX98Compat>, DefaultIgnore;
|
||||||
def ext_nonclass_type_friend : ExtWarn<
|
def ext_nonclass_type_friend : ExtWarn<
|
||||||
"non-class friend type %0 is a C++11 extension">, InGroup<CXX11>;
|
"non-class friend type %0 is a C++11 extension">, InGroup<CXX11>;
|
||||||
|
def warn_cxx98_compat_nonclass_type_friend : Warning<
|
||||||
|
"non-class friend type %0 is incompatible with C++98">,
|
||||||
|
InGroup<CXX98Compat>, DefaultIgnore;
|
||||||
def err_friend_is_member : Error<
|
def err_friend_is_member : Error<
|
||||||
"friends cannot be members of the declaring class">;
|
"friends cannot be members of the declaring class">;
|
||||||
def warn_cxx98_compat_friend_is_member : Warning<
|
def warn_cxx98_compat_friend_is_member : Warning<
|
||||||
|
@ -632,6 +638,9 @@ def warn_cxx98_compat_friend_is_member : Warning<
|
||||||
def ext_unelaborated_friend_type : ExtWarn<
|
def ext_unelaborated_friend_type : ExtWarn<
|
||||||
"specify '%select{struct|union|class|enum}0' to befriend %1; accepted "
|
"specify '%select{struct|union|class|enum}0' to befriend %1; accepted "
|
||||||
"as a C++11 extension">, InGroup<CXX11>;
|
"as a C++11 extension">, InGroup<CXX11>;
|
||||||
|
def warn_cxx98_compat_unelaborated_friend_type : Warning<
|
||||||
|
"befriending %1 without '%select{struct|union|class|enum}0' keyword is "
|
||||||
|
"incompatible with C++98">, InGroup<CXX98Compat>, DefaultIgnore;
|
||||||
def err_qualified_friend_not_found : Error<
|
def err_qualified_friend_not_found : Error<
|
||||||
"no function named %0 with type %1 was found in the specified scope">;
|
"no function named %0 with type %1 was found in the specified scope">;
|
||||||
def err_introducing_special_friend : Error<
|
def err_introducing_special_friend : Error<
|
||||||
|
@ -2800,6 +2809,9 @@ def ext_complex_component_init : Extension<
|
||||||
"complex initialization specifying real and imaginary components "
|
"complex initialization specifying real and imaginary components "
|
||||||
"is an extension">, InGroup<DiagGroup<"complex-component-init">>;
|
"is an extension">, InGroup<DiagGroup<"complex-component-init">>;
|
||||||
def err_empty_scalar_initializer : Error<"scalar initializer cannot be empty">;
|
def err_empty_scalar_initializer : Error<"scalar initializer cannot be empty">;
|
||||||
|
def warn_cxx98_compat_empty_scalar_initializer : Warning<
|
||||||
|
"scalar initialized from empty initializer list is incompatible with C++98">,
|
||||||
|
InGroup<CXX98Compat>, DefaultIgnore;
|
||||||
def err_illegal_initializer : Error<
|
def err_illegal_initializer : Error<
|
||||||
"illegal initializer (only variables can be initialized)">;
|
"illegal initializer (only variables can be initialized)">;
|
||||||
def err_illegal_initializer_type : Error<"illegal initializer type %0">;
|
def err_illegal_initializer_type : Error<"illegal initializer type %0">;
|
||||||
|
|
|
@ -268,7 +268,7 @@ bool Sema::isAcceptableNestedNameSpecifier(NamedDecl *SD) {
|
||||||
if (!isa<TypeDecl>(SD))
|
if (!isa<TypeDecl>(SD))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Determine whether we have a class (or, in C++0x, an enum) or
|
// Determine whether we have a class (or, in C++11, an enum) or
|
||||||
// a typedef thereof. If so, build the nested-name-specifier.
|
// a typedef thereof. If so, build the nested-name-specifier.
|
||||||
QualType T = Context.getTypeDeclType(cast<TypeDecl>(SD));
|
QualType T = Context.getTypeDeclType(cast<TypeDecl>(SD));
|
||||||
if (T->isDependentType())
|
if (T->isDependentType())
|
||||||
|
|
|
@ -9652,7 +9652,6 @@ FriendDecl *Sema::CheckFriendTypeDecl(SourceLocation FriendLoc,
|
||||||
QualType T = TSInfo->getType();
|
QualType T = TSInfo->getType();
|
||||||
SourceRange TypeRange = TSInfo->getTypeLoc().getLocalSourceRange();
|
SourceRange TypeRange = TSInfo->getTypeLoc().getLocalSourceRange();
|
||||||
|
|
||||||
if (!getLangOptions().CPlusPlus0x) {
|
|
||||||
// C++03 [class.friend]p2:
|
// C++03 [class.friend]p2:
|
||||||
// An elaborated-type-specifier shall be used in a friend declaration
|
// An elaborated-type-specifier shall be used in a friend declaration
|
||||||
// for a class.*
|
// for a class.*
|
||||||
|
@ -9670,22 +9669,30 @@ FriendDecl *Sema::CheckFriendTypeDecl(SourceLocation FriendLoc,
|
||||||
|
|
||||||
std::string InsertionText = std::string(" ") + RD->getKindName();
|
std::string InsertionText = std::string(" ") + RD->getKindName();
|
||||||
|
|
||||||
Diag(TypeRange.getBegin(), diag::ext_unelaborated_friend_type)
|
Diag(TypeRange.getBegin(),
|
||||||
|
getLangOptions().CPlusPlus0x ?
|
||||||
|
diag::warn_cxx98_compat_unelaborated_friend_type :
|
||||||
|
diag::ext_unelaborated_friend_type)
|
||||||
<< (unsigned) RD->getTagKind()
|
<< (unsigned) RD->getTagKind()
|
||||||
<< T
|
<< T
|
||||||
<< FixItHint::CreateInsertion(PP.getLocForEndOfToken(FriendLoc),
|
<< FixItHint::CreateInsertion(PP.getLocForEndOfToken(FriendLoc),
|
||||||
InsertionText);
|
InsertionText);
|
||||||
} else {
|
} else {
|
||||||
Diag(FriendLoc, diag::ext_nonclass_type_friend)
|
Diag(FriendLoc,
|
||||||
|
getLangOptions().CPlusPlus0x ?
|
||||||
|
diag::warn_cxx98_compat_nonclass_type_friend :
|
||||||
|
diag::ext_nonclass_type_friend)
|
||||||
<< T
|
<< T
|
||||||
<< SourceRange(FriendLoc, TypeRange.getEnd());
|
<< SourceRange(FriendLoc, TypeRange.getEnd());
|
||||||
}
|
}
|
||||||
} else if (T->getAs<EnumType>()) {
|
} else if (T->getAs<EnumType>()) {
|
||||||
Diag(FriendLoc, diag::ext_enum_friend)
|
Diag(FriendLoc,
|
||||||
|
getLangOptions().CPlusPlus0x ?
|
||||||
|
diag::warn_cxx98_compat_enum_friend :
|
||||||
|
diag::ext_enum_friend)
|
||||||
<< T
|
<< T
|
||||||
<< SourceRange(FriendLoc, TypeRange.getEnd());
|
<< SourceRange(FriendLoc, TypeRange.getEnd());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// C++0x [class.friend]p3:
|
// C++0x [class.friend]p3:
|
||||||
// If the type specifier in a friend declaration designates a (possibly
|
// If the type specifier in a friend declaration designates a (possibly
|
||||||
|
|
|
@ -902,12 +902,13 @@ void InitListChecker::CheckScalarType(const InitializedEntity &Entity,
|
||||||
InitListExpr *StructuredList,
|
InitListExpr *StructuredList,
|
||||||
unsigned &StructuredIndex) {
|
unsigned &StructuredIndex) {
|
||||||
if (Index >= IList->getNumInits()) {
|
if (Index >= IList->getNumInits()) {
|
||||||
if (!SemaRef.getLangOptions().CPlusPlus0x) {
|
|
||||||
if (!VerifyOnly)
|
if (!VerifyOnly)
|
||||||
SemaRef.Diag(IList->getLocStart(), diag::err_empty_scalar_initializer)
|
SemaRef.Diag(IList->getLocStart(),
|
||||||
|
SemaRef.getLangOptions().CPlusPlus0x ?
|
||||||
|
diag::warn_cxx98_compat_empty_scalar_initializer :
|
||||||
|
diag::err_empty_scalar_initializer)
|
||||||
<< IList->getSourceRange();
|
<< IList->getSourceRange();
|
||||||
hadError = true;
|
hadError = !SemaRef.getLangOptions().CPlusPlus0x;
|
||||||
}
|
|
||||||
++Index;
|
++Index;
|
||||||
++StructuredIndex;
|
++StructuredIndex;
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -40,8 +40,8 @@ void Lambda() {
|
||||||
int InitList() {
|
int InitList() {
|
||||||
(void)new int {}; // expected-warning {{generalized initializer lists are incompatible with C++98}}
|
(void)new int {}; // expected-warning {{generalized initializer lists are incompatible with C++98}}
|
||||||
(void)int{}; // expected-warning {{generalized initializer lists are incompatible with C++98}}
|
(void)int{}; // expected-warning {{generalized initializer lists are incompatible with C++98}}
|
||||||
int x {}; // expected-warning {{generalized initializer lists are incompatible with C++98}}
|
int x { 0 }; // expected-warning {{generalized initializer lists are incompatible with C++98}}
|
||||||
return {}; // expected-warning {{generalized initializer lists are incompatible with C++98}}
|
return { 0 }; // expected-warning {{generalized initializer lists are incompatible with C++98}}
|
||||||
}
|
}
|
||||||
|
|
||||||
int operator""_hello(const char *); // expected-warning {{literal operators are incompatible with C++98}}
|
int operator""_hello(const char *); // expected-warning {{literal operators are incompatible with C++98}}
|
||||||
|
@ -160,3 +160,13 @@ void TrivialButNonPODThroughEllipsis() {
|
||||||
struct HasExplicitConversion {
|
struct HasExplicitConversion {
|
||||||
explicit operator bool(); // expected-warning {{explicit conversion functions are incompatible with C++98}}
|
explicit operator bool(); // expected-warning {{explicit conversion functions are incompatible with C++98}}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Struct {};
|
||||||
|
enum Enum { enum_val = 0 };
|
||||||
|
struct BadFriends {
|
||||||
|
friend enum ::Enum; // expected-warning {{befriending enumeration type 'enum ::Enum' is incompatible with C++98}}
|
||||||
|
friend int; // expected-warning {{non-class friend type 'int' is incompatible with C++98}}
|
||||||
|
friend Struct; // expected-warning {{befriending 'Struct' without 'struct' keyword is incompatible with C++98}}
|
||||||
|
};
|
||||||
|
|
||||||
|
int n = {}; // expected-warning {{scalar initialized from empty initializer list is incompatible with C++98}}
|
||||||
|
|
Loading…
Reference in New Issue